Advertisement
Guest User

Merge Title

a guest
May 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Sub Step3_MergeTitle()
  2. Attribute Step3_MergeTitle.VB_ProcData.VB_Invoke_Func = " \n14"
  3. '
  4. ' MergeTitle Macro
  5. '
  6.  
  7. '
  8. 'Where is Title
  9. Dim i, n As Integer
  10. Dim rangeSource As Range
  11.  
  12. n = Sheets.Count
  13. i = 1
  14. Do Until i > n
  15. Set wsSource = Worksheets(i)
  16. wsSource.Activate
  17. ' Detect range of content
  18. Set rangeSource = wsSource.UsedRange.SpecialCells(xlCellTypeVisible)
  19.  
  20. With rangeSoucre
  21. Dim R, C As Long
  22. Dim Title As Range
  23.  
  24.  
  25. For C = 1 To rangeSource.Columns.Count
  26. For R = 1 To rangeSource.Rows.Count
  27. If Application.WorksheetFunction.IsText(rangeSource.Cells(R, C)) Then
  28.  
  29. LastRow = rangeSource.Cells(R, C).End(xlDown).Row
  30. If LastRow > 4 Then
  31. LastRow = LastRow - 1
  32. End If
  33. Set Title = rangeSource.Range(Cells(R, C), Cells(LastRow, C))
  34. Exit For
  35. End If
  36. Next R
  37. If Application.WorksheetFunction.IsText(rangeSource.Cells(R, C)) Then
  38. Exit For
  39. End If
  40. Next C
  41. On Error Resume Next
  42. With Title
  43. Application.DisplayAlerts = False
  44. .UnMerge
  45. .Columns(1).ColumnWidth = 250
  46. .Justify
  47. Columns(1).ColumnWidth = 10
  48. End With
  49.  
  50. End With
  51. i = i + 1
  52. Loop
  53.  
  54. MsgBox "You have merge titles for all sheets"
  55. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement