Ask Experts Questions for FREE Help !
Ask
    moorecp's Avatar
    moorecp Posts: 1, Reputation: 1
    New Member
     
    #1

    Feb 6, 2010, 04:57 PM
    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.
    Gekko's Avatar
    Gekko Posts: 347, Reputation: 77
    Full Member
     
    #2

    Feb 6, 2010, 05:09 PM

    Instead of;

    Range("A3:E3").Select

    Try;

    ActiveCell.Select
    Range(Selection, Selection.Offset(0, 4)).Select
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #3

    Feb 7, 2010, 01:51 AM

    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

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Excel macro full cell reference [ 1 Answers ]

I am running a macro when the sheet is opened. In my macro I want to reference a cell on a different sheet without selecting that sheet. In other words I do not want to leave the Active sheet (call it Sheet1) and return to the Sheet1 which will "Activate" the Sheet1 again, triggering my macro again...

Stuck on Relational Cell Macro [ 11 Answers ]

Hello - needing some help on a Excel2007 macro I'm trying to create. I'm not an expert at it so may be a simple answer (hopeflly)... In this macro, I'm trying to copy and highlight a range of cells by using my left/right arrows incombination with shift and ctrl but since the data can be various...

Macro to save a file name as per a cell content. [ 3 Answers ]

I have a macro saving the file auto. To my desktop. For example cell A1 = 501 I run a macro with a counter and auto. Changes A1 to 502. Now macro must change file saving to 502, or =cell A1 content. I also sometimes have to change destination from desktop to a specific file.

Cell references within VBA in an Excel macro [ 1 Answers ]

In a macro in Excel I want to refer to a cell where the user entered a number. I want that number to be the row number for the macro to move to. (I will then select the entire row and copy it to row 1, which I know how to do). How can I tell the macro which row to go to, using the number...

Cell to trigger a macro [ 2 Answers ]

Hi there I am newbie here and I have a question regarding Excel VBA. Though I done a search, but none of it could meet what I wanted. My request is.. Let say I enter value in A1 & B1. In cell C1, I have a formula, =sum(A1:B1), which is the total. Now, I want to create a event change (VBA)...


View more questions Search