Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Skip call macro based on cell value

I saw 1 similar question but it didn’t address my issue so I decided to post it.

  • I have a VBA macro that calls for different macros in a workbook.
  • I would like to skip calling specific macros if specific cells in the "Setup" worksheet are empty.
  • I came up with the code below. The macro runs fine if the cells are not empty but it actually still calls the macros even when the specific cells are empty.

I would greatly appreciate if someone could point me in the right direction!
Thank you in advance.

Sub CE_Import()

Dim rng As Range 

Set ws = ThisWorkbook.Sheets("Setup") 
Set rng = Range("A3") 
For Each cell In rng 
If cell.Value <> "" Then 
Call MSI_Import 
End If

Next

Set ws = ThisWorkbook.Sheets("Setup") 
Set rng = Range("D3") 
For Each cell In rng 
If cell.Value <> "" Then 
Call IGH_Import 
End If

Next

Set ws = ThisWorkbook.Sheets("Setup") 
Set rng = Range("G3") 
For Each cell In rng 
If cell.Value <> "" Then 
Call TCell_Import 
End If

Next

Call Hidden_Import

End Sub
'''

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can greatly reduce your current code.

What I’m unsure about is if the later methods are meant to be called even if the previous methods weren’t.

E.g. do you want IGH_Import or Hidden_Import to be called even if MSI_Import wasn’t called? I think that may be the root of your issue, either that or those cells aren’t really empty.

Sub CE_Import()

If ThisWorkbook.Sheets("Setup").Range("A3").Value2 <> "" Then Call MSI_Import
If ThisWorkbook.Sheets("Setup").Range("D3").Value2 <> "" Then Call IGH_Import 
If ThisWorkbook.Sheets("Setup").Range("G3").Value2 <> "" Then Call TCell_Import 

Call Hidden_Import

End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading