only run lines of code is a specific cell value is not blank

londa_vba

Board Regular
Joined
May 11, 2023
Messages
61
Office Version
  1. 365
Platform
  1. Windows
I have the following code
the first 8 lines are always needed. Is there a simple way to have Excel check whether Cell 5,54 has a value first and if so run the following 6 lines of code and if not skip to check whether Cell 5,55 has a value and again if so run the following 6 lines of code and if not skip down.

VBA Code:
        Sheets("File").Cells(Exportrow, 1) = "   <LOCUS>"
        Exportrow = Exportrow + 1
        Sheets("File").Cells(Exportrow, 1) = "   <LOCUSNAME>" & Sheets("Entry").Cells(5, 53) & "</LOCUSNAME>"
        Exportrow = Exportrow + 1
        Sheets("File").Cells(Exportrow, 1) = "   <READINGBY>" & user & "</READINGBY>"
        Exportrow = Exportrow + 1
        Sheets("File").Cells(Exportrow, 1) = "   <READINGDATETIME>" & yr & "-" & mn & "-" & dd & "T" & hr & ":" & mi & ":" & sc & "</READINGDATETIME>"
        
[COLOR=rgb(65, 168, 95)]'i would like the macro to check cell 5,54 on sheet Entry first, proceed is not blank, skip if is blank[/COLOR]
        Sheets("File").Cells(Exportrow, 1) = "   <ALLELE>"
        Exportrow = Exportrow + 1
        Sheets("File").Cells(Exportrow, 1) = "   <ALLELEVALUE>" & Sheets("Entry").Cells(5, 54) & "</ALLELEVALUE>"
        Exportrow = Exportrow + 1
        Sheets("File").Cells(Exportrow, 1) = "   </ALLELE>"
        Exportrow = Exportrow + 1
  
[COLOR=rgb(65, 168, 95)]'i would like the macro to check cell 5,55 on sheet Entry first, proceed is not blank, skip if is blank      [/COLOR]
        Sheets("File").Cells(Exportrow, 1) = "   <ALLELE>"
        Exportrow = Exportrow + 1
        Sheets("File").Cells(Exportrow, 1) = "   <ALLELEVALUE>" & Sheets("Entry").Cells(5, 55) & "</ALLELEVALUE>"
        Exportrow = Exportrow + 1
        Sheets("File").Cells(Exportrow, 1) = "   </ALLELE>"
        Exportrow = Exportrow + 1
        Sheets("File").Cells(Exportrow, 1) = "   </LOCUS>"
        Exportrow = Exportrow + 1
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You can add these two lines to each section of the macro. Example for the first section; then just match column reference in the other sections:
VBA Code:
'I would like the macro to check cell 5,54 on sheet Entry first, proceed is not blank, skip if is blank
If Sheets("Entry").Cells(5, 54) <> "" Then     '<- added, checks if not blank
    Sheets("File").Cells(Exportrow, 1) = "   <ALLELE>"
    Exportrow = Exportrow + 1
    Sheets("File").Cells(Exportrow, 1) = "   <ALLELEVALUE>" & Sheets("Entry").Cells(5, 54) & "</ALLELEVALUE>"
    Exportrow = Exportrow + 1
    Sheets("File").Cells(Exportrow, 1) = "   </ALLELE>"
    Exportrow = Exportrow + 1
End If                                        '<- added
 
Upvote 1

Forum statistics

Threads
1,215,693
Messages
6,126,237
Members
449,304
Latest member
hagia_sofia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top