Log in

View Full Version : Start macro from current cell


moorecp
Feb 6, 2010, 04:57 PM
Brand new to macros. I want to create a macro that will change the formatting of 5 cells starting with the cell I am sitting in when I hit "run macro". Below is my macro now.

Sub Macro1()
'
' Macro1 Macro
'

'
Range("A3:E3").Select
With Selection.Font
.FontStyle = "Regular"
.Strikethrough = True
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.499984741
End With
End Sub
But no matter where I am in the worksheet, when I run the macro - it starts at A3 and ends with E3. I want to be able to start the macro in, say C21, and have it change the formatting in cells C21 through G21 - without having to have a separate macro for each group of cells I want to change formatting.

Gekko
Feb 6, 2010, 05:09 PM
Instead of;

Range("A3:E3").Select

Try;

ActiveCell.Select
Range(Selection, Selection.Offset(0, 4)).Select

JBeaucaire
Feb 7, 2010, 01:51 AM
Like so:


Sub FormatCells()

With ActiveCell.Resize(5, 1).Font
.Strikethrough = True
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.499984741
End With

End Sub

If the only "formatting" change you're making is doing the strikethrough, you can edit out even more:


Sub FormatCells()
ActiveCell.Resize(5, 1).Font.Strikethrough = True
End Sub