How can my code do multiple if functions?

jase888

New Member
Joined
Jun 6, 2017
Messages
22
Ive got some code that checks if a cell is a number if it is then it runs a msgbox if its text or empty then displays a msgbox and halts.

I'm struggling to work out how i can get it to check other cells to display different msgboxs? As in check cell C5 is not empty else display msg box.

Code:
Private Sub cmdinvoiceadd_Click()    If IsNumeric(Range("C4").Value) And Not IsEmpty(Range("C4")) Then
        FinishInvoice
        invoiceclear
       Else
        MsgBox "Please enter Invoice number"
    End If
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
This all depends how C5 relates to C4.
Should the C5 test be part of the existing If or should it be independent of the C4 test?
 
Upvote 0
Good point it basically needs to check C4, C5, C9 & C10 and if anyone of them is missing txt not proceed. But it needs to show a error message to say which is missing so the user knows thats why i need different msg boxs
 
Upvote 0
Am no VBA expert, base something on this

Code:
sub k1()
Dim i as string
i=""
if IsEmpty(Range("C4")) then
    i = "C4 "
End If
if IsEmpty(Range("C5")) then
    i = i & "C5 "
End If
if IsEmpty(Range("C9")) then
    i = i & "C9 "
End If
if IsEmpty(Range("C10")) then
    i = i & "C10"
End If
If (i<>"") then
    MsgBox "The following cells are empty: " & i
End If
end sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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