if, and, or material list error checking

Martin Bennett

New Member
Joined
Jan 16, 2019
Messages
2
Hi All
Hoping someone can offer some advice, both my colleague and myself are far from experts with VBA. We have an excel workbook that collates multiple material lists using VBA and consolidates a final version for stores this is all working fine. We are now trying to add some error checking into the workbook for example if column B contains part numbers 123 & 125 does it contain part number 127 or 131 if it does take no action, if it does not Flag up a message Part number 127 or 131 missing notify engineering.

We have tried a number of different methods but can't get this to work i.e. if, and, or. I'm sure there is a very simple method and we are overlooking something


Part No.
123
124
125
126
127
128
129
130

<tbody>
</tbody>


Thanks in advance
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try..
Code:
Sub CheckPartNo()

Dim b1 As Boolean, b2 As Boolean, b3 As Boolean, myStr As String, Rng As Range
Set Rng = Range("B:B")
With Application.WorksheetFunction
    b1 = (.CountIf(Rng, 123) <> 0 And .CountIf(Rng, 125) <> 0) = True
    b2 = .CountIf(Rng, 127) = 0
    b3 = .CountIf(Rng, 131) = 0
End With
    
If b1 Then
    If b2 Then myStr = 127
    If b3 Then myStr = 131
    If b2 And b3 Then myStr = 127 & vbCr & 131
End If

If Len(myStr) > 0 Then MsgBox myStr, , "Missing"

End Sub

Message box appears if either or both 127 and 131 are missing
If only want to know if both are missing then remove
Code:
    If b2 Then myStr = 127
    If b3 Then myStr = 131
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

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