Variable Range select

diamonddave

New Member
Joined
Jul 23, 2010
Messages
4
Good Morning, I'm working in excel 2003 and am trying for formate the sub total line associated with the sub total function. The row number will be variable, but the column range is fixed from Column B to AP. I can get to the starting point using the following: Note data does not exist in all columns B to AP

Cells.Find(What:="4 Total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, -1).Select
ActiveCell.FormulaR1C1 = "Sub Total"
ActiveCell.Offset(1, 0).Select

I have tried the following but no luck.

'range(ActiveCell & (LastColumn)).Select
'range(ActiveCell.Offset(-5, 0) & ActiveCell.Offset(35, 0)).Select

being new to programing, I'm note sure if I'm on the right track. any Ideas.
 

Some videos you may like

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,277
If the Active cell is A10. This will select A5:A45 (41 cells)
Code:
Range(ActiveCell.Offset(-5, 0), ActiveCell.Offset(35, 0)).Select

So will this...
Code:
ActiveCell.Offset(-5, 0).Resize(41, 1).Select


On another note: You don't need to select the cells to do something with them.
This...
Code:
ActiveCell.Offset(0, -1).Select
ActiveCell.FormulaR1C1 = "Sub Total"
Could be replaced with just this...
Code:
ActiveCell.Offset(0, -1) = "Sub Total"
 

Watch MrExcel Video

Forum statistics

Threads
1,108,979
Messages
5,526,023
Members
409,675
Latest member
audeser

This Week's Hot Topics

Top