Hello,
I have written a block of code to check if a sting appears in an array and if so, to make modifications on the line where a match is found. The Reference range and the array are on two separate worksheets. When I run this on a dummy spreadsheet to test the code, it works fine, however when I add it to my master spreadsheet (which has about 20 tabs, lots of database references, pivot tables and code already developed) I am getting a "Runtime-error '9': Subscript out of range" error. The specific line if code is in BOLD below. I have already checked and double checked that the worksheet names are correct and I am using the "Option Explicit" function to ensure no variables are undefined. Any thoughts? Thanks in advance!
(ps - the actual excel file has too much sensitive information to post screenshots so I cannot provide)
Option Explicit
Sub testing()
Dim b As Variant
Dim i As Long
Dim lr As Long
Dim lc As Long
Dim a As Range
Application.ScreenUpdating = False
lr = Sheets("Master Query").Cells(Rows.Count, "B").End(xlUp).Row
lc = Sheets("Master Query").Cells(1, Columns.Count).End(xlToLeft).Column
b = Sheets("Master Query").Range("B8:B" & lr)
For i = 2 To lr
Set a = Sheets("Inputs").Range("C32:C34").Find(b(i, 1), LookAt:=xlWhole)
If Not a Is Nothing Then
Sheets("Master Query").Cells(i, 3).Value = 20
Sheets("Master Query").Cells(i, 4).Value = 30
Sheets("Master Query").Cells(i, 5).Value = 40
Set a = Nothing
End If
Next i
Application.ScreenUpdating = True
End Sub
Bookmarks