Hi Jindon,
Your solution worked but a small issue still remains:
Sorry that I could not explain it clearly but please see below code wherein I used cell property so that I can use my Variable in MyRng .
Now the first problem is solved but the other problem is I want to use Variable tRng in formula (b2) as under but I could not concatenate the same and it is giving one or the other issue . Can you pls help. First commented formula is working fine but the non commented one is not working. The reason is b2 in formula is also dynamic. Hope you understand . Thanks
Sub test1()
Dim ws1 As String, myRng As String
ws1 = "TestCases"
colmncnt = ThisWorkbook.Sheets(ws1).Cells(3, Columns.Count).End(xlToLeft).Column
With Sheets(ws1)
myRng = .Range(.Cells(3, 5), .Cells(7, colmncnt)).Address 'Sheets(ws1).Range("e3:r7").Address
End With
'//USe Variable for
NewRow =2
tRng = Range("b" & NewRow).Address(False, True)
Debug.Print tRng
With Sheets("TCTemplate")
With .Range("c2", .Range("b" & Rows.Count).End(xlUp)(1, 2))
' .Formula = "=iferror(hlookup(""*""&b2,'" & ws1 & "'!" & myRng & ",5,false),"""")"
.Formula = "=iferror(hlookup(""*"" " & tRng & " ,'" & ws1 & "'!" & myRng & ",5,false),"""")"
End With
End With
End Sub
Bookmarks