0

I am trying to write a macro on "PERSONAL.XLSB" in excel-vba. I am retrieving a range from one of the open workbook and later I want to loop through that range.

Sub test()

Dim ran_a As Range

ran_a = Workbooks("TWE-Tool_V05_Modified.xlsm").Worksheets("Frame").Range("A1:AZ2")
end sub

However it keeps showing me the

Run time error '91' Object variable or With block variable not set

How to solve the issue?

user2436437
  • 357
  • 1
  • 6
  • 15

1 Answers1

3

When you assign an object to a object variable you must use Set statement.

Try thus:
Set ran_a = Workbooks("TWE-Tool_V05_Modified.xlsm").Worksheets("Frame").Range("A1:AZ2")

More information: Set Statement (Visual Basic)

Trimax
  • 2,413
  • 7
  • 35
  • 59