Make VBA refer to first cell only in .Selection?

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961
For i = 1 To Selection.Rows.Count
ActiveCell.Offset(i - 1, 0).RowHeight=foo(i)

That's bad code. It's supposed to set the selection's row heights from array foo, and it's fine ... UNLESS ... ActiveCell is not the first row in the selection.

So I'd like one of two solutions, if you don't mind helping me:
A. set Activecell to first cell in selection, preserving selection
(then code is okay as is. Is this something like activecell.row=selection.row?)
OR
B. change the code.
(Unfortunately
Selection.Offset(i - 1, 0).RowHeight=foo(i)
sets Selection.Rows.Count rows en masse! It should only do 1 at a time)

Hep me! Hep me!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
What exactly are you trying to do here?

Do you need to work with Selection?
 
Upvote 0
Exactly what I said Norie. Just like the next response, which will answer the question instead of asking another [rhetorical] one.
 
Upvote 0
Look I'm sorry but, to me at least, the post is rather unclear.

Sometimes it helps when one has an overview of the whole thing.
 
Upvote 0
That's precisely what I need, Andrew - thanks. One thing though - change the first "i,1" to "1,1" or lose the offset, as this skips every other row as written.

In fact that's excellent - the syntax to directly refer to any part of the selection. I'll just drop the offset entirely!

Way to go - thanks.
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,780
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top