Understanding VBA Cell Range("") Expression Deployment

Asked 1 months ago, Updated 1 months ago, 4 views

Is it possible to expand the range expression in vba?It seems that you can string, but is it possible to range it?What I want to do is the code below.

Color only certain cells=>cells()

 'This code succeeded
subcellcolor
for i = 3 to 27 step 4
 for j = 1 to 13
  cells(i,j).interior.colorindex=3
  cells(i+1,j).interior.colorindex=4
  cells(i+2,j).interior.colorindex=5
next j —next i
end sub

Code that failed to deploy expressions in range

subsippai
set range=range.format("a{i}", "m{i}")
for i = 3 to 27 step 4
    r.interior.colorindex=3
next i
End sub

vba

2022-09-30 13:47

1 Answers

You have rows() to select the

row.

substep_row
for i = 3 to 27 step 4
  rows(i).interior.colorindex=3
next i
end sub

However, there is a problem that the entire line has been selected and cannot be stopped where you want to.


2022-09-30 13:47

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.