Hello all,
I am getting an error with my code: 1004 Method 'Range' of object '_Worksheet' failed at the lines indicated below. The code still doesn't work when I set j = 11 & k = 40, but the code DOES work if I set the range to A11:A40. Any ideas as how to remedy this? I need to be able to change a lot of variables with the macro, including the range being searched, which is why I have a mess of ranges specified as cells.
Points for helping! 
Sub Macro1()
Application.ScreenUpdating = False
Dim i, j, k, m, n As Integer
Dim wb1, wb2 As Workbook
Dim ws1a, ws1b, ws2 As Worksheet
Dim Txt As String
Dim s, t As Range
Set wb1 = ThisWorkbook
Set ws1a = wb1.Sheets("Data Locations")
Set ws1b = wb1.Sheets(ws1a.Cells(8, 2).Value)
Set wb2 = Workbooks(ws1a.Cells(3, 2).Value)
Set ws2 = wb2.Sheets(ws1a.Cells(4, 2).Value)
j = ws1a.Cells(13, 3).Value
' j = 11
k = ws1a.Cells(13, 4).Value
' k = 40
m = ws1a.Cells(11, 4).Value
n = ws1a.Cells(15, 4).Value
For i = 2 To 100
Application.Goto ws1b.Cells(i, 1)
Txt = ActiveCell.Value
' Set s = ws2.Range("A11:A40").Find(Txt)
Set s = ws2.Range(Cells(j, 1), Cells(k, 1)).Find(Txt) <----
If s Is Nothing Then
Else
Application.Goto ws2.Range(Cells(j, 1), Cells(k, 1)) <----
' Application.Goto ws2.Range("A11:A40")
' ws2.Range("A11:A40").Find(Txt).Activate
ws2.Range(Cells(j, 1), Cells(k, 1)).Find(Txt).Activate <----
Set t = ActiveCell.Offset(0, m - 1)
Application.Goto ws1b.Cells(i, n)
ws1b.Cells(i, n).Value = t.Value
End If
Next i
Application.Goto ws1b.Cells(2, n)
Application.ScreenUpdating = True
End Sub
Bookmarks