#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    32
    Rep Power
    6

    Add text to multiple cells in Excel


    I'm trying to write simple macros to add xml/html tags to cells in Excel. What I would like to have is that the user literally selects multiple cells in the same column, then fires the macro and it automatically adds the information before and after the text in the cells.

    I've accomplished this part but it only adds it to the first (Active) cell in the selected cells. I can't seem to figure out how to make all the cells active so it knows to add text to the other selected cells as well.

    Here is what I have for the macro so far:
    Code:
    Sub format2()
    
    FormulaR1C1 = _
            "<headline><![CDATA[<p><font color=""#00ffff"">"
    FormulaR1C2 = _
            "</font>]]></headline>"
    ActiveCell = FormulaR1C1 & ActiveCell & FormulaR1C2
    With ActiveCell.Characters(Start:=1, Length:=19).Font
    .Name = "Arial"
    .FontStyle = "Regular"
    .Size = 10
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
    .ColorIndex = xlAutomatic
    End With
    
    End Sub
    I'm VERY new to VB so any and all help is greatly appreciated!

    Thanks,
    Kumba
  2. #2
  3. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    Code:
        With Selection.Font
            .Name = "Arial"
            .FontStyle = "Regular"
            .Size = 10
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
    This will apply your formatting to the current selection

    To select a range you can do something like

    Code:
        ActiveSheet.Range("A1:C33").Select
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss

IMN logo majestic logo threadwatch logo seochat tools logo