By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

expertatexcel.com

 


Load cell value to a vba variable

There are a few ways to do this.

value_from_range = Range("A1")

Value_from_cell = Cells(3,2)

In the above code value_from_range is a variable that gets the contents of A1 from the active sheet.

If you were to change sheets you'd get a different value.

value_from_range = [A1]

value_from_range = [Sheet1!A1]

value_from_range = sheets("Sheet1").Range("A1")

value_from_range = [='[a file name.xlsx]Sheet Name'!$A$1]

value_from_range = Workbooks("a wb.xlsx").Sheets("Sheet1").Range("A1")

You can use Cells instead

The With statement can be useful:

With Workbooks("a wb.xlsx").Sheets("Sheet1")
    .Range("A1").Select
    .Cells(3,2) = 5
    .Range(sRange) = 2
End With