VBA: To add validation to enter required data

Stranger8421

New Member
Joined
Jun 30, 2022
Messages
23
Office Version
  1. 365
Hey Guys,

Need help. I need to add validation. For example:- If Cust_info is provided they should be one cust_id for that id or else should throw error message D column.

As per the given sheet
IdCust_idCust_infoErrors
1​
abb
212​
322​
2​
215​
3​
abc
233​
4​
344​
sds
323​

Senarios :- 1. For ID 1 (a2) for the Cust_info 212 (C2) and 322 (C3) have abb(b2) as Cust_id so no errors.
2. For ID 2 (a4) for the cust_info 215(C5) the cust_id is not provided either in B4 and B5 So error should be thrown
3. For ID 3 (a6) for the cust_info 233(C7) the cust_id is provided in B6 So no error.
4. For ID 4 (a8) for the cust_info 344(C5) the cust_id is not provided either in B8 and B9 So error should be thrown. and next cust_info 323 the cust_id is provided.

Final should be like
IdCust_idCust_infoErrors
1​
abb
212​
322​
2​
212​
please provide cust_id for this cust_info
3​
abc
233​
4​
344​
please provide cust_id for this cust_info
sds
323​

My Code till rows selection : -

Dim lastrowFinal As Long, rng As Range, i As Long

lastrowFinal = ws1.Range("A:M").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row


For i = 4 To lastrowShipSpot

If Cells(i, "A") <> "" Then

rng = Cells(i, "A").End(xlDown).Row - 1

If Cells(i + 1, "A") <> "" Then rng = i
If rng > 10000 Then rng = lastrowShipSpot

------need to code here -------

End If
End If
Next i

Thanks alot for seeing my thread.
Regards,
Joe
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hey Guys,

Need help. I need to add validation. For example:- If Cust_info is provided they should be one cust_id for that id or else should throw error message D column.

As per the given sheet
IdCust_idCust_infoErrors
1​
abb
212​
322​
2​
215​
3​
abc
233​
4​
344​
sds
323​

Senarios :- 1. For ID 1 (a2) for the Cust_info 212 (C2) and 322 (C3) have abb(b2) as Cust_id so no errors.
2. For ID 2 (a4) for the cust_info 215(C5) the cust_id is not provided either in B4 and B5 So error should be thrown
3. For ID 3 (a6) for the cust_info 233(C7) the cust_id is provided in B6 So no error.
4. For ID 4 (a8) for the cust_info 344(C5) the cust_id is not provided either in B8 and B9 So error should be thrown. and next cust_info 323 the cust_id is provided.

Final should be like
IdCust_idCust_infoErrors
1​
abb
212​
322​
2​
212​
please provide cust_id for this cust_info
3​
abc
233​
4​
344​
please provide cust_id for this cust_info
sds
323​

My Code till rows selection : -

Dim lastrowFinal As Long, rng As Range, i As Long

lastrowFinal = ws1.Range("A:M").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row


For i = 4 To lastrowShipSpot

If Cells(i, "A") <> "" Then

rng = Cells(i, "A").End(xlDown).Row - 1

If Cells(i + 1, "A") <> "" Then rng = i
If rng > 10000 Then rng = lastrowShipSpot

------need to code here -------

End If
End If
Next i

Thanks alot for seeing my thread.
Regards,
Joe
Update code ;

Dim lastrowFinal As Long, rng As Range, i As Long

lastrowFinal = ws1.Range("A:D").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row


For i = 2 To lastrowShipSpot

If Cells(i, "A") <> "" Then

rng = Cells(i, "A").End(xlDown).Row - 1

If Cells(i + 1, "A") <> "" Then rng = i
If rng > 10000 Then rng = lastrowShipSpot

------need to code here -------

End If
End If
Next i
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

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