I have a macro which I've been using to merge two cells together in a word table, but what I want to do is to get the cursor to move down by one cell, so that I can repeatedly press the shortcut key to repeat the command over and over.
The macro code that I have (shamelessy copied and pasted from a web page), is as follows:
Sub MergeWithCellToRight()
'
' MergeWithCellToRight Macro
'
'
Dim oRng As Range
Dim oCell As Cell
Set oCell = Selection.Cells(1)
If oCell.ColumnIndex = Selection.Rows(1).Cells.Count Then
MsgBox "There is no cell to the right?", vbCritical, "Error"
Exit Sub
End If
Set oRng = oCell.Range
oRng.MoveEnd wdCell, 1
oRng.Cells.Merge
Selection.Collapse wdCollapseStart
End Sub
I've attempted to add the following line just before the 'End Sub' statement
Selection.MoveDown wdCell, 1
but this generates the error, Run-time error '4120' Bad Parameter
whenever I execute the macro.
Can anyone tell me how to correct this or what I'm doing wrong?
Answer
No idea if that could help, but I have the following:
Sub Merges2Cols()
Dim nbLines As Integer
nbLines = 10 'you'd have to count the number of lines you want to merge
For i = 1 To nbLines
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Cells.Merge
Selection.MoveDown Unit:=wdLine, Count:=1
Next
End Sub
No comments:
Post a Comment