ianawwalker
New Member
- Joined
- Feb 16, 2023
- Messages
- 15
- Office Version
- 365
- 2021
- Platform
- Windows
Hello,
I have a data set that I need to update every month or bi-monthly and I am attempting to create a vba to have this data updated. Essentially, I have other VBA that puts my data into a worksheet ("US_CBtoRecords") and if the column value is within this worksheet i need to update my other worksheet ("Records") to reflect "Y" in column AH. From researching and looking online i've created a vba that i believe should work to help me find the match and then update the column, but continue to get an error showing that my subscript is out of range. I'm attempting to but both worksheets into arrays, which is my first time doing this, and then only change the value in column AH for the corresponding match. Below is my vba, any help is much appreciated!
I have a data set that I need to update every month or bi-monthly and I am attempting to create a vba to have this data updated. Essentially, I have other VBA that puts my data into a worksheet ("US_CBtoRecords") and if the column value is within this worksheet i need to update my other worksheet ("Records") to reflect "Y" in column AH. From researching and looking online i've created a vba that i believe should work to help me find the match and then update the column, but continue to get an error showing that my subscript is out of range. I'm attempting to but both worksheets into arrays, which is my first time doing this, and then only change the value in column AH for the corresponding match. Below is my vba, any help is much appreciated!
VBA Code:
Sub testing2()
'testing sub
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Dim i As Long
Dim j As Long
Dim LRow1 As Long
Dim LRow2 As Long
Dim varray As Variant
Dim varray2 As Variant
LRow1 = Worksheets("Records").Range("A" & Rows.Count).End(xlUp).Row
LRow2 = Worksheets("US_CBtoRecords").Range("A" & Rows.Count).End(xlUp).Row
varray = Application.Transpose(Worksheets("Records").Range("A2:A" & LRow1).Value)
varray2 = Application.Transpose(Worksheets("US_CBtoRecords").Range("A2:A" & LRow2).Value)
For i = 1 To LRow1
For j = 1 To LRow2
If varray(i) = varray2(j) Then
varray(i) = "Y"
Exit For
End If
Next j
Next i
Worksheets("Records").Range("AH2:AH" & LRow1).Value = Application.Transpose(varray)
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub