Visual Basics code needed

Rivie

New Member
Joined
Jul 29, 2020
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
i need to make an list to keep up with inventory. I have 4 columns. Column A is the facility it was sent to, column b is the it item number ( 1- 120), column c is for the date sent out to the facility and the column d is the date that the item was sent back to our office. what i need is a code that checks for a duplicate item number in column b and if it finds one to check column d for a return date. if return dates are found for all item numbers no action is to be preform. if no return dates are found for two or more of the item numbers then the item numbers cells need to be turned yellow. if return date is found for all but one item then no action is to be preformed. i'm trying to make sure that all items are being signed in and out with out discrepancies. i'm fairly new to using visual basics but i think it can be done but i can't figure it out.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi Rivie,

I had a go, and think this does what you want? It is predicated on the fact you have filters turned on.

VBA Code:
Sub CheckOut_Validation()
'Aim: To verify if Items have been checked in /out correctly
'Process: Loop filter items. Check count for non blanks vs item count. Color accordingly

Dim ws As Worksheet
Dim RNG_O As Range      'Items Out
Dim RNG_R As Range      'Items Returned
Dim i As Integer        'Loop 1-120
Dim lr As Long          'Last Row Col B

Set ws = ActiveSheet
lr = ws.Range("B" & Rows.Count).End(xlUp).Row
Set RNG_O = ws.Range("B2:B" & lr)
Set RNG_R = ws.Range("D2:D" & lr)


On Error Resume Next
For i = 1 To 120
    RNG_O.AutoFilter Field:=2, Criteria1:=i
    If Application.WorksheetFunction.CountA(RNG_O.SpecialCells(xlCellTypeVisible)) - Application.WorksheetFunction.CountA(RNG_R.SpecialCells(xlCellTypeVisible)) > 1 Then
        RNG_O.SpecialCells(xlCellTypeVisible).Interior.Color = vbYellow
    End If
Next i

RNG_O.AutoFilter.Show
End Sub
 

Attachments

  • CheckoutValidation.gif
    CheckoutValidation.gif
    84.7 KB · Views: 11
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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