IF Range is not blank exit sub

cloos

Banned user
Joined
Jun 24, 2013
Messages
99
Hi -

I have been struggling with this bit of code all day today and just cannot see what is wrong I have copied several bits and modified them and they all come up with the incorrect results.

In a range("A3:A4") there are formulas that post messages if specific conditions are not met. If either cell in the range has a a posted message I want a msgbox("fix errors") and then exit sub, else continue with rest of my code. The results either pop the message box every time I run it whether the conditions are met or not or not at all, and errors. Below is one example I was using and added a count to it for each cell. Any help would be very much appreciated.

Dim rnge As Range


Set rnge = Range("A3:A4")
If Range("A3:A4") <> "" Then
MsgBox "Please correct Errors"
Exit Sub
Else

End If

This is making me batty!
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Range("A3:A4") would be an object, not a value.

Code:
Sub test1()
    Dim i As Integer, val As String
    
    For i = 10 To 15
        val = Sheets("TestSheet").Cells(i, 4).Value  'checking in column D so 4
        If (val = "") Then 
            ' nothing
        Else
            MsgBox "Message: " & i & val
            Exit Sub
        End If
    Next
End Sub
 
Upvote 0
Code:
  If Len(Range("A3").Text & Range("A4").Text) Then
    MsgBox "Please correct errors"
    Exit Sub
  End If

  ' carry on
 
Upvote 0

Forum statistics

Threads
1,196,445
Messages
6,015,299
Members
441,886
Latest member
fbell

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