I want to iterate over the command buttons and replace the command button captions with the current i value. Each command button is named D plus a number (D1, D2, D3, D4, D5). I tried to use
With Sheet1
For i = 1 To 5
Controls("D" & (i)).Caption = i
Next
End With
But I get a compile error: Sub or function not defined.
The sub I am writing is contained in module1 and the command buttons are placed directly in Sheet1 with ActiveX command buttons (Microsoft Forms 2.0 Command Button). I have used the line: Controls("D" & (i)).Caption before with a form with no issues but I don’t want to use a form for this project. Is there a way to concatenate a letter and a variable in a for loop to match the names of the command buttons created and the current number being set to the caption of that button?