Compile error in code

ndendrinos

Well-known Member
Joined
Jan 17, 2003
Messages
1,694
With this code I get a compile error
"function call on left hand side of assignment must return variant or object"

MsgBox= is highlighted

Code:
If [A16].Value = "B/Order" Then
    Application.DisplayAlerts = False
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = ActiveSheet.Range("A17:A35")

For Each rng2 In rng1
If rng2 = "" Then
MsgBox = "hello"
Next
Else
ActiveSheet.Delete

End If
    Application.DisplayAlerts = True

What I'm trying to do is this:
for each cell in [A17:A35] if the adjacent cell (same row column B) is empty then show a msggbox

Thank you
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Remove the equal sign in the MsgBox line.

MsgBox "hello"

Also missing an End If after the MsgBox

Code:
    Dim rng2 As Range

    If Range("A6").Value = "B/Order" Then
        
        For Each rng2 In Range("A17:A35")
            If rng2 = "" Then
                MsgBox "hello"
            [COLOR="Red"]End If[/COLOR]
        Next
        
    Else
        ActiveSheet.Delete
    End If
    
    Application.DisplayAlerts = True
 
Last edited:
Upvote 0
thanks working on it
not working yet (no errors) but not doing what I need it to do and that is:

for any populated cell in [A17:A35] if the adjacent in columnB is empty then show a msgbox and exit sub (do not delete sheet)
Sorry about that
 
Last edited:
Upvote 0
Code:
    Dim cell As Range

    If Range("A6").Value = "B/Order" Then
        
        For Each cell In Range("A17:A35")
            If cell.Value <> "" And cell.Offset(0, 1).Value = "" Then
                MsgBox cell.Address & " is not blank." & vbCr & _
                       cell.Offset(0, 1).Address & " is blank."
                Exit Sub
            End If
        Next cell
        
    Else
        ActiveSheet.Delete
    End If
 
Upvote 0
working (with thanks for your patience) with what you have just given me but I don't get the message box

A16 has a value of 1 .... B16 is empty I run the code and do not get the message but rather I get the prompt for deleting or not the sheet
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,949
Latest member
Dupuhini

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