VBS code cycle thru sheets doesn't work

Glenn Nelson 0 Reputation points
2023-03-03T15:29:01.26+00:00

I am trying to cycle thru sheets to perform code. It works on the first sheet, but not the others. The code fails (stops) at the Set rngTarget expression.

For Each sheet In ActiveWorkbook.Worksheets
    If sheet.Index > 1 Then
        Set rngTarget = sheet.Range(Cells(1, 8), Cells(1, arrSize))
Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 126.2K Reputation points
    2023-03-03T15:54:14.2266667+00:00

    Try this:

    Set rngTarget = sheet.Range(sheet.Cells(1, 8), sheet.Cells(1, arrSize))
    
    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.