Home » excel » excel – VBA – get range using Dim values – range of object __global failed

excel – VBA – get range using Dim values – range of object __global failed

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have the following Dims

Dim PlayersStartAt As Integer
Dim PlayersEndAt As Integer

PlayersStartAt = 101
PlayersEndAt = PlayersStartAt + 50


Selection.AutoFill Destination:=Range("B & PlayersStartAt:B & PlayersEndAt"), Type:=xlFillDefault

and want to execute the following line of code.

It with great with Range("B101:B151");

What is wrong with my syntax?

How to&Answers:

Change this

Range("B & PlayersStartAt:B & PlayersEndAt")

to

Range("B" & PlayersStartAt & ":B" & PlayersEndAt)

PlayersStartAt and PlayersEndAt are variables. Anything that you put between quotes will be taken as a string 🙂