Dim collet As String
collet = ThisWorkbook.ColLetter(ColCount) + ":" + LTrim(Str(Target.Row))
Set my_r = Target(collet).Select
I’m getting the runtime error at the last line in my code.Cannot figure out why
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It would help to know exactly what you’re trying to accomplish here, but I can make a few suggestions.
First, when referencing a single cell as I believe you are trying to do, a colon is not required. So
colletshould contain something like “B2”, not “B:2”.Second, when you call
Selecton aRangeobject it uses the parameter as an offset, not an absolute reference. So ifTargetis cell B2, andcollectis B2, thenTarget("B2").Selectwill actually select cell C3.And lastly, I’m assuming by the presence of the
Targetobject that this code is inside an event handler. Make sure that by selecting a different range you are not triggering the same event again. You could end up with an infinite loop that ends only when you reach the bottom or the end of your spreadsheet. This scenario can cause the runtime error 1004 that you are seeing.