Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select column 1 to 10 of ActiveCell row in Excel

Tags:

excel

vba

this is regarding a macro in an excel.

While a combination of keys are pressed (i.e. the macro is triggered), I need to do some format changes to the columns 1 to 10 of the row that has the ActiveCell.

At the moment I have am selecting the entire row

ActiveCell.EntireRow.Select

However, I need to select only the row 1 to 10. I think it ought to be something like

ActiveCell.Range(1, 10).Select

But that does not work.

Just to be clear, I have read about

ActiveCell.Offset(5, -4).Select

But that is not going to work in my case. The ActiveCell could be any column of the row and hence a hardcoded offset is not going to help.

So, the excel gurus there, I am hoping this is a quick stuff, just that somehow I can't find the answer. Please help.

like image 741
partha Avatar asked Dec 09 '22 15:12

partha


1 Answers

If it is always columns 1 to 10 (i.e. A to J) then this ought to work:

Range("A" & ActiveCell.Row & ":J" & ActiveCell.Row)

For example if the activecell is M14 then this will select the range A14:J14. You can then format this how you like.

Hope this helps

like image 104
Alex P Avatar answered Dec 25 '22 08:12

Alex P