Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. Sub MergeWithCellToRight()
  2. '
  3. ' MergeWithCellToRight Macro
  4. '
  5. '
  6. Dim oRng As Range
  7. Dim oCell As Cell
  8. Set oCell = Selection.Cells(1)
  9. If oCell.ColumnIndex = Selection.Rows(1).Cells.Count Then
  10. MsgBox "There is no cell to the right?", vbCritical, "Error"
  11. Exit Sub
  12. End If
  13. Set oRng = oCell.Range
  14. oRng.MoveEnd wdCell, 1
  15. oRng.Cells.Merge
  16. Selection.Collapse wdCollapseStart
  17. End Sub
  18.  
  19. Selection.MoveDown wdCell, 1
  20.  
  21. Sub Merges2Cols()
  22. Dim nbLines As Integer
  23. nbLines = 10 'you'd have to count the number of lines you want to merge
  24. For i = 1 To nbLines
  25. Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
  26. Selection.Cells.Merge
  27. Selection.MoveDown Unit:=wdLine, Count:=1
  28. Next
  29. End Sub
  30.  
  31. Selection.Move Unit:=wdCell, Count:=Selection.Tables(1).Columns.Count
  32.  
  33. Selection.Move Unit:=wdCell, Count:=-1 * Selection.Tables(1).Columns.Count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement