Check Cell Value before starting VBA Code

An Quala

Board Regular
Joined
Mar 21, 2022
Messages
146
Office Version
  1. 2021
Platform
  1. Windows
Hi, so I have recorded my macros which are running smoothly, I just want to add one more function in this macro which will be with VBA, so what I want to do is I want to check the values in 3 sheets, 'sheet1!'D1, sheet2!D1, sheet3!D1 have values then run the code otherwise show a message box "The sheets are empty"

Because right now the macros are being run even if the sheets are empty, and I don't want to do that.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You can do put this at the top of your VBA procedure:
VBA Code:
If Sheets("Sheet1").Range("D1") = "" Or Sheets("Sheet2").Range("D1") = "" Or Sheets("Sheet3").Range("D1") = "" Then
    MsgBox "At least one of the sheets is empty!"
    Exit Sub
End If
 
Upvote 0

Forum statistics

Threads
1,215,701
Messages
6,126,308
Members
449,308
Latest member
VerifiedBleachersAttendee

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