The code below brings up an error when trying to copy row over to new sheet. The excel sheet has 3 sheets, info (data export), filter(string names), results(blank sheet)
The code is supposed to match substring from filter worksheet with main string on info worksheet. If the substring is contained in the main string, it will copy the entire row over to the results worksheet. The error comes up when it's trying to copy over.
I could be overcomplicating the process, any help is greatly appreciated. Thanks in advance.
Error: Run-time error '1004': Application-defined or object-defined error
Sub RoundedRectangle1_Click()
Dim info As Range
Dim filter As Range
Dim results As Range
Set info = Worksheets("Info").Cells(4, 5)
Set filter = Worksheets("Filter").Cells(2, 1)
Set results = Worksheets("Results").Cells(1, 1)
Dim i, j, k As Integer
i = 0
j = 0
k = 0
Do While info.Offset(i, 0) <> ""
If InStr(1, LCase(info.Offset(i, 0)), LCase(filter.Offset(k, 0))) <> 0 Then
info.Offset(i, 0).EntireRow.Copy results.Cells(j, 1)
i = i + 1
j = j + 1
k = 0
Else
If filter.Offset(k, 0) = "" Then
i = i + 1
k = 0
Else
k = k + 1
End If
End If
Loop
End Sub
results.Range("A" & j & ":W" & j) = info.Range("A" & i & ":W" & i).Valuebut it resulted in the same error - InternGrantDim i, j, k As Integer- note onlykisAs Integer.iandjare both implicitlyVariant. Also should probably beAs Longinstead. - Mathieu Guindon