PDA

View Full Version : Help getting script to exit if cell is blank



joelly
09-23-2012, 10:48 PM
Hello , i have the below which is working well for me, however i would like to improve it.

How can i make it so when cell B2 on the sheet is blank to end the script, but continue if there is data.?

Any help would be appreciated.


Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\letters\6 month reminders.xls")

objExcel.Application.Visible = False
objWorkbook.Sheets("Sheet1").QueryTables(1).Refresh
Wscript.Sleep 7000
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close

mancubus
09-23-2012, 11:40 PM
hi.

wellcome to VBAX.

you can use green VBA button in quick reply panel to surround your code with VBA tags.

Exit Sub
statement.

assuming cell B2 is on Sheet1


'...
'...
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\letters\6 month reminders.xls")
If Trim(objWorkbook.Sheets("Sheet1").Range("B2")) = "" Then Exit Sub
'...
'...