Home » excel » excel vba – Put String argument in Range – VBA

excel vba – Put String argument in Range – VBA

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a little problem in VBA, I want to put row and column of Range function in String format like that :

    debut = "BH" & LTrim(Str(i))
    fin = "DB" & LTrim(Str(i))
    For Each Cell In Ws.Range("debut:fin")

But i have an error, how can i resolve it ?
Thanks

How to&Answers:

The way you have done it ("debut:fin"), the range is really equal to that string and is invalid. What you need to do is concatenate the 2 strings with a : in between with the & operator:

For Each Cell In Ws.Range(debut & ":" & fin)