always_confused
Board Regular
- Joined
- Feb 19, 2021
- Messages
- 68
- Office Version
- 2016
- Platform
- Windows
Hello. I would like to copy a column to another worksheet when the header matches a string input. I have the code below:
However I get the error "Subscript out of range" at the line where I copy. How can I resolve this problem?
VBA Code:
Sub find_col(name As String)
Sheets("name").Range("A:A").Clear
With Sheets("lot")
.Activate
For i = 1 To .UsedRange.Columns.count
If Cells(1, i).value = name Then
Sheets("name").Range("A:A").value = Sheets("lot").Columns(i).value 'error here
End If
Next i
End With
End Sub
However I get the error "Subscript out of range" at the line where I copy. How can I resolve this problem?