If I have a worksheet that looks like this simplified version:
Column A
-----------
Value 1
Value 1
Value 1
Value 1
VALUE 2
VALUE 2
VALUE 2
Test
Test
Test
Test
And I want to be able to use a macro to merge cells that have the same value in column A to produce output like this:
Column A
-----------
Value 1
[Merged Cell]
[Merged Cell]
[Merged Cell]
VALUE 2
[Merged Cell]
[Merged Cell]
Test
[Merged Cell]
[Merged Cell]
[Merged Cell]
* Note that column A has rows 2 through 4 merged (as in 'Format Cells' --> 'Merge Cells') with row 1. Likewise, rows 5 through 7 are merged as well as rows 8 through 11.
The psedudocode to do this would look something like the following but I need help making this into working code:
Sub Merge_RowsX()
TgtStr As String, Dim i As Long, BeginRowNum As Integer,
EndRowNum As Integer (and additional variables as needed)
Application.ScreenUpdating = False
For i = 1 To [A65536].End(xlUp).Row
1.] Get the value of first cell in column A
* Store TgtStr
* Store BeginRowNum
2.] Iterate through subsequent rows in column A until value is different from TgtStr
* Store EndRowNum
3.] Merge cells BeginRowNum to EndRowNum
Next i Repeat loop (i.e. get new TgtStr)
Application.ScreenUpdating = True
End Sub
Any help is greatly appreciated, I hope my explanation is clear.
Column A
-----------
Value 1
Value 1
Value 1
Value 1
VALUE 2
VALUE 2
VALUE 2
Test
Test
Test
Test
And I want to be able to use a macro to merge cells that have the same value in column A to produce output like this:
Column A
-----------
Value 1
[Merged Cell]
[Merged Cell]
[Merged Cell]
VALUE 2
[Merged Cell]
[Merged Cell]
Test
[Merged Cell]
[Merged Cell]
[Merged Cell]
* Note that column A has rows 2 through 4 merged (as in 'Format Cells' --> 'Merge Cells') with row 1. Likewise, rows 5 through 7 are merged as well as rows 8 through 11.
The psedudocode to do this would look something like the following but I need help making this into working code:
Sub Merge_RowsX()
TgtStr As String, Dim i As Long, BeginRowNum As Integer,
EndRowNum As Integer (and additional variables as needed)
Application.ScreenUpdating = False
For i = 1 To [A65536].End(xlUp).Row
1.] Get the value of first cell in column A
* Store TgtStr
* Store BeginRowNum
2.] Iterate through subsequent rows in column A until value is different from TgtStr
* Store EndRowNum
3.] Merge cells BeginRowNum to EndRowNum
Next i Repeat loop (i.e. get new TgtStr)
Application.ScreenUpdating = True
End Sub
Any help is greatly appreciated, I hope my explanation is clear.