locked
Help w/Merge Cells Macro RRS feed

  • Question

  • Can someone help me with a short macro please?  I've got a table which can have different amounts of columns (5 to 10) and lots of rows of course.  I'd like to click the left cell in any given row then run a macro which will:

    1. Select all cells to the right
    2. Merge the cells
    3. Enter text, "Notes:" into the cell along with
    4. Enter one: Carriage Return

    That's it.  Any help please?  (I can't write VBA for crap!) 
    Thanks for your help in advance!!! 
    ~Dax

     




    Wednesday, August 10, 2011 9:12 PM

Answers

  • Try this:

    Sub mergeCells()
      Dim doc As Word.Document
      Dim rng As Word.Range
      
      Set doc = Word.ActiveDocument
      Set rng = Word.Selection.Range
      
      If rng.Information(wdWithInTable) Then
        rng.StartOf unit:=Word.wdRow
        rng.EndOf unit:=Word.wdRow, Extend:=Word.wdExtend
        rng.Cells.Merge
        rng.Text = "Notes:" & vbCr
      End If
    
    End Sub
    

     


    Kind Regards, Rich ... http://greatcirclelearning.com
    • Marked as answer by Dax ArrowayII Friday, August 12, 2011 9:26 PM
    Thursday, August 11, 2011 1:53 AM

All replies

  • Try this:

    Sub mergeCells()
      Dim doc As Word.Document
      Dim rng As Word.Range
      
      Set doc = Word.ActiveDocument
      Set rng = Word.Selection.Range
      
      If rng.Information(wdWithInTable) Then
        rng.StartOf unit:=Word.wdRow
        rng.EndOf unit:=Word.wdRow, Extend:=Word.wdExtend
        rng.Cells.Merge
        rng.Text = "Notes:" & vbCr
      End If
    
    End Sub
    

     


    Kind Regards, Rich ... http://greatcirclelearning.com
    • Marked as answer by Dax ArrowayII Friday, August 12, 2011 9:26 PM
    Thursday, August 11, 2011 1:53 AM
  • That's the one!  Thank you millions!! ~Dax
    Friday, August 12, 2011 3:30 PM