Please modify my current code! If any of the cell from A3 to F3 is "" then exit sub

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
If any of the cell from A3 to F3 is "" then exit sub, how do we set this up?:)
Thanks
Pedie

Current
Code:
Sub CommandButton2_Click()

If Range("b3") = "" Then
MsgBox "You must assign a Detail Number in cell B3"
Range("b3").Select
        Exit Sub
Else
Run "Report"

End If

End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try

Code:
If WorksheetFunction.CountA(Range("A3:F3")) <> 6 Then Exit Sub
 
Upvote 0
Something like this?

Code:
Sub CommandButton2_Click()
Dim i As Long
For i = 1 To 6
    If Cells(3, i).Value = "" Then
        MsgBox "You must assign a Detail Number in cell " & Cells(3, 1).Address(RowAbsolute:=False, ColumnAbsolute:=False)
        Cells(3, 1).Select
        Exit Sub
    End If
Next i
Run "Report"
End Sub
 
Upvote 0
Here is one of many ways to do this:

Code:
If WorksheetFunction.Countblank(Range("A3:F3")) > 0 Then exit sub
Hope that helps.
 
Upvote 0
This should work:

Code:
Sub CommandButton2_Click()
Dim r As Range
    For Each r In Range("A3:F3")
        If r.Value = "" Then
            MsgBox "You must assign a Detail Number in cell " & r.Address
            r.Select
            Exit Sub
        End If
    Next r
    Run "Report"
End Sub
 
Upvote 0
Thank you everyone for helping!
I really appriciate it. Thanks alot again!;)
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,375
Members
448,888
Latest member
Arle8907

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