Check list macro

tstigman

New Member
Joined
Jun 10, 2011
Messages
2
I'm still a beginer in programming in general, Ive been trying to get a macro to check a list of numbers A7: Axx

I was able to do it with conditional formatting and creating a list in another column however that is not what i want to accomplish. I want the macro to check A7:Axx against a list of "restricted numbers" worked into the macro. so if the worksheet changes the macro is still usable with the new data.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You could start at the first cell, and use OFFSET to go down one number at a time and check to see if that number is in your list. Then you LOOP this for however many lines you've got.
 
Upvote 0
I understand that part and it works all the way down however my delima is this is an example of how its set up.

column A: Column B:
A B
B F
C G
D A


I want to remove column B from the sheet. and put the variables in some sort of "list" within the macro so as new data is downloaded im able to still identify the variables that are in Column B against new data in Column A
 
Upvote 0
The following will but the values of column B into an array which can then be accessed via its position colBVals(3) would = "G" from your example.

Code:
Sub test()
    Dim rng As Range
    Dim ws As Worksheet
    Dim firstRow As Long, lastRow As Long
    Dim col As Long
    Dim i As Long
    Dim colBVals() As String
    
    col = Columns("A").Column   '// Column that contains data
    firstRow = 7                '// First row of interest
    
    Set ws = Worksheets("Sheet1")
    
    With ws
    
    '// Last row in column specified in col that contains anything
    lastRow = .Cells(Rows.count, col).End(xlUp).Row
    
    Set rng = .Range(Cells(firstRow, col), .Cells(lastRow, col))
    
    ReDim colBVals(1 To rng.count)

    For i = 1 To rng.count
        '// Store values in column B in variable
        colBVals(i) = rng.Cells(i, 1).Offset(0, 1).Value
    Next i
    
    End With

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,473
Members
452,915
Latest member
hannnahheileen

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