Understanding VBA Cell Range("") Expression Deployment

Asked 2 years ago, Updated 2 years ago, 48 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


© 2024 OneMinuteCode. All rights reserved.