0

This works fine to set all rows to 25 pixels.

Sub sbChangeRowHeightMulti()
Rows("3:1000").RowHeight = 25
End Sub

But I want to take the existing row height and add 10 to it.

So something like this pseudocode:

Sub sbChangeRowHeightMulti()
Rows("3:1000").RowHeight = Rows(x).RowHeight + 10
End Sub

Is that possible? Been trying to figure out the syntax for it, but no luck.

2 Answers 2

1

Unfortunately, there is no simple one statement way to do this. Just as in Excel itself there is no way to select multiple rows and drag/set the row height to an increment of the individual heights.

The simplest solution is to loop over all the rows:

Option Explicit
'v0.1.0
Sub sbChangeRowHeightMulti()
  Application.ScreenUpdating = False
    Dim rowRow As Range
    For Each rowRow In Rows("3:1000")
      rowRow.RowHeight = rowRow.RowHeight + 10
    Next rowRow
  Application.ScreenUpdating = True
End Sub
-3

Try this:

Sub sbChangeRowHeightMulti()
Rows("3:1000").RowHeight = Rows("3:1000").RowHeight + 10
End Sub
4
  • Did you do something special to get this to work?  It doesn’t work for me.   Please do not respond in comments; edit your answer to make it clearer and more complete. Jun 26, 2018 at 0:49
  • @Scott Resonding in comments because I have nothing to add to my answer at this point: Perhaps I misunderstood the question. I did not do anything special to get it to work. It adds 10 to the existing row height of the designated rows. Was that not the original question?
    – wysiwyg
    Jun 26, 2018 at 19:29
  • (1) I think we agree on the meaning of the question (although your statement of it is a little imprecise, so I’m not sure you and I are thinking the same thing). (2) I’m a little confused.  I thought that, when I tested your answer yesterday, it did nothing.  I’ve retested it, and it definitely does something, so I guess (at best) I was sloppy yesterday. (3) What your answer seems to do is compute Rows("3").RowHeight + 10 and set the height of every row to that value.  I believe that the question is asking to add a constant to the height of each row,  … (Cont’d) Jun 26, 2018 at 20:52
  • (Cont’d) …  so if the current heights are 15, 21, 27, 33, …, they would be changed to 25, 31, 37, 43, ….   (Rereading the question, I concede that it’s unclear; but note that robinCTS interpreted it the same way I did.)   Your answer would change them to 25, 25, 25, 25, …. (4) You’ve obviously noticed that somebody down voted your answer.   It wasn’t I.  So somebody other than me believes that your answer is wrong. Jun 26, 2018 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.