Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Spreadsheets (https://www.askmehelpdesk.com/forumdisplay.php?f=395)
-   -   Start macro from current cell (https://www.askmehelpdesk.com/showthread.php?t=443981)

  • Feb 6, 2010, 04:57 PM
    moorecp
    start macro from current cell
    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.
  • Feb 6, 2010, 05:09 PM
    Gekko

    Instead of;

    Range("A3:E3").Select

    Try;

    ActiveCell.Select
    Range(Selection, Selection.Offset(0, 4)).Select
  • Feb 7, 2010, 01:51 AM
    JBeaucaire

    Like so:

    Code:

    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:
    Code:

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


  • All times are GMT -7. The time now is 11:23 AM.