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.
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

BobUmlas

Well-known Member
Joined
Mar 14, 2002
Messages
1,170
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,421
Messages
5,528,676
Members
409,829
Latest member
CFreeamaz

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top