Error message if two cells are blank

Alwinaz

Board Regular
Joined
Feb 7, 2012
Messages
201
Hi

I have the following macro

Code:
Sub add()
Call unprotect
'
' add Macro
'


'
[COLOR=#ff0000]If ActiveCell.Value = "[/COLOR]" Then
    MsgBox "Error: Please enter the Number of Questions and the Number Bonds", vbOKOnly, "Error..."
    Exit Sub
Else


Dim lRow As Integer
    Range("B4").Select
    ActiveCell.FormulaR1C1 = "+"
    
    lRow = Range("A" & Rows.count).End(xlUp).Row
        If lRow = 1 Then GoTo NextPartOfCode
            Range("b4:B4").AutoFill Destination:=Range("B4:B" & lRow)


    'ActiveWindow.SmallScroll Down:=0
    Range("C4").Select
NextPartOfCode:
Call add_equalsign
Call ValueOfSum
Call protect
End If


End Sub
How do i change the part in red to stop the macro from running if any one of Cell F1 and F2 is blank. I tried If F1 = "" and F2 ="" then, but it only stop if one is blank. I need to stop the macro when either is blank. I also tried If F1 = "" or F2 ="" then.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

BobUmlas

Well-known Member
Joined
Mar 14, 2002
Messages
1,181
if Application.Counta(Range("F1:F2"))<2 then

or

If Range("F1").value = "" or Range("F2"),Value = "" then
 

Alwinaz

Board Regular
Joined
Feb 7, 2012
Messages
201
Hi there

I'v tried If Range("F1").value = "" or Range("F2").Value = "" then, but it still does not stop. It only stop when both is blank.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,650
Messages
5,838,566
Members
430,556
Latest member
Peachforyou

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
Top