VBA cleanup using If statements help

sycodiz

New Member
Joined
Jun 15, 2008
Messages
27
I have an excel sheet that has a lot of different cells that I need to do a validation on.
I would like the pop ups to continue to pop up if there are issues with the cells based on the validations I created.
I originally created this macro with one If statement and the rest were all ElseIf until the end where I just used Else.
It worked, but as soon as it found an issue, the msgbox would display that issue and then close. I need it to continue to go through the rest of the code and pop up each time.
Here is a shortened version of the code of how I think I need to create this. I was wondering if anyone had any suggestions on how to shorten this code up?

Sub NewItemFormReview()
'
' NewItemFormReview Macro
'
Worksheets("New Item - View All").Select

If Range("C5").Value <> "New Item or Expand" Then
ElseIf Range("I13").Value < 1000 Or Range("I13") > 10001 Then MsgBox "MIP - CM ID: Cell I13 must be 4 digits"
End If
If Range("C5").Value <> "New Item or Expand" Then
ElseIf Application.WorksheetFunction.IsText(Range("c14")) = False Then MsgBox "Category Manager: Cell C14 must contain a name"
End If
If Range("C5").Value <> "New Item or Expand" Then
ElseIf IsEmpty(Range("e14").Value) = True Then MsgBox "Phone number E14 is empty"
End If
If Range("C5").Value <> "New Item or Expand" Then
ElseIf Application.WorksheetFunction.IsText(Range("G14")) = False Then MsgBox "Category Support Specialist: Cell G14 must contain a name"
End If
If Range("C5").Value <> "New Item or Expand" Then
ElseIf IsEmpty(Range("I14").Value) = True Then MsgBox "Phone number I14 is empty"
End If
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
If C5 does equal "New Item or Expand" then you don't want to do any of the other checks then maybe

VBA Code:
Sub NewItemFormReview()
    Worksheets("New Item - View All").Select
    If Range("C5").Value <> "New Item or Expand" Then
        If Range("I13").Value < 1000 Or Range("I13") > 10001 Then MsgBox "MIP - CM ID: Cell I13 must be 4 digits"
        If Not Application.WorksheetFunction.IsText(Range("c14")) Then MsgBox "Category Manager: Cell C14 must contain a name"
        If IsEmpty(Range("e14").Value) Then MsgBox "Phone number E14 is empty"
        If Not Application.WorksheetFunction.IsText(Range("G14")) Then MsgBox "Category Support Specialist: Cell G14 must contain a name"
        If IsEmpty(Range("I14").Value) Then MsgBox "Phone number I14 is empty"
    End If
End Sub
 
Upvote 0
Solution
If C5 does equal "New Item or Expand" then you don't want to do any of the other checks then maybe

VBA Code:
Sub NewItemFormReview()
    Worksheets("New Item - View All").Select
    If Range("C5").Value <> "New Item or Expand" Then
        If Range("I13").Value < 1000 Or Range("I13") > 10001 Then MsgBox "MIP - CM ID: Cell I13 must be 4 digits"
        If Not Application.WorksheetFunction.IsText(Range("c14")) Then MsgBox "Category Manager: Cell C14 must contain a name"
        If IsEmpty(Range("e14").Value) Then MsgBox "Phone number E14 is empty"
        If Not Application.WorksheetFunction.IsText(Range("G14")) Then MsgBox "Category Support Specialist: Cell G14 must contain a name"
        If IsEmpty(Range("I14").Value) Then MsgBox "Phone number I14 is empty"
    End If
End Sub
I know I can never express everything I need the first round.
In C5, it could be another option, which then I have another round of cells to check so that is not an option.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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