#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Merging Macro

I have a list with some blank cells in between. I need to have the entries
appearing at top be merged with the blank cells (if any) below. For example
the table:

BRANCH 1 PRODUCT 1
PRODUCT 2
PRODUCT 7
PRODUCT 3
BRANCH 2 PRODUCT 1
PRODUCT 2
PRODUCT 6
PRODUCT 3
BRANCH 3 PRODUCT 4
BRANCH 4 PRODUCT 5
BRANCH 5 PRODUCT 1
PRODUCT 2
PRODUCT 6
PRODUCT 3

be redesigned as with the branch names to be merged only against their
relative PRODUCTS. Do NOTE that Branch 3 & 4 have no empty cell beneath it
and consist only one product.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Merging Macro

Assuming you have data from row1. onwards in .ColA and ColB without headers
try the below macro and feedback

Sub Macro1()

Dim lngRow As Long
Dim lngLastRow As Long
Dim lngTempRow As Long

lngTempRow = 1

lngLastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
For lngRow = 1 To lngLastRow
If Range("A" & lngRow) < "" Then
If lngRow 1 And lngTempRow < lngRow - 1 Then
Range("A" & lngTempRow & ":A" & lngRow - 1).Merge
Range("A" & lngTempRow & ":A" & lngRow - 1).VerticalAlignment = xlCenter
End If
lngTempRow = lngRow
End If
Next
If lngRow 1 And lngTempRow < lngRow - 1 Then
Range("A" & lngTempRow & ":A" & lngRow - 1).Merge
Range("A" & lngTempRow & ":A" & lngRow - 1).VerticalAlignment = xlCenter
End If


End Sub


If this post helps click Yes
---------------
Jacob Skaria


"FARAZ QURESHI" wrote:

I have a list with some blank cells in between. I need to have the entries
appearing at top be merged with the blank cells (if any) below. For example
the table:

BRANCH 1 PRODUCT 1
PRODUCT 2
PRODUCT 7
PRODUCT 3
BRANCH 2 PRODUCT 1
PRODUCT 2
PRODUCT 6
PRODUCT 3
BRANCH 3 PRODUCT 4
BRANCH 4 PRODUCT 5
BRANCH 5 PRODUCT 1
PRODUCT 2
PRODUCT 6
PRODUCT 3

be redesigned as with the branch names to be merged only against their
relative PRODUCTS. Do NOTE that Branch 3 & 4 have no empty cell beneath it
and consist only one product.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Merging Macro

Once again!
XClent Jacob!

However, can you help me in devising a code so as to have it worked on any
specific cells selected instead of only limited for Column A?

"Jacob Skaria" wrote:

Assuming you have data from row1. onwards in .ColA and ColB without headers
try the below macro and feedback

Sub Macro1()

Dim lngRow As Long
Dim lngLastRow As Long
Dim lngTempRow As Long

lngTempRow = 1

lngLastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
For lngRow = 1 To lngLastRow
If Range("A" & lngRow) < "" Then
If lngRow 1 And lngTempRow < lngRow - 1 Then
Range("A" & lngTempRow & ":A" & lngRow - 1).Merge
Range("A" & lngTempRow & ":A" & lngRow - 1).VerticalAlignment = xlCenter
End If
lngTempRow = lngRow
End If
Next
If lngRow 1 And lngTempRow < lngRow - 1 Then
Range("A" & lngTempRow & ":A" & lngRow - 1).Merge
Range("A" & lngTempRow & ":A" & lngRow - 1).VerticalAlignment = xlCenter
End If


End Sub


If this post helps click Yes
---------------
Jacob Skaria


"FARAZ QURESHI" wrote:

I have a list with some blank cells in between. I need to have the entries
appearing at top be merged with the blank cells (if any) below. For example
the table:

BRANCH 1 PRODUCT 1
PRODUCT 2
PRODUCT 7
PRODUCT 3
BRANCH 2 PRODUCT 1
PRODUCT 2
PRODUCT 6
PRODUCT 3
BRANCH 3 PRODUCT 4
BRANCH 4 PRODUCT 5
BRANCH 5 PRODUCT 1
PRODUCT 2
PRODUCT 6
PRODUCT 3

be redesigned as with the branch names to be merged only against their
relative PRODUCTS. Do NOTE that Branch 3 & 4 have no empty cell beneath it
and consist only one product.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Merging Macro

In the below code change all "A" to the required column..Change "B" to column
where you have the continous list...

If this post helps click Yes
---------------
Jacob Skaria


"FARAZ QURESHI" wrote:

Once again!
XClent Jacob!

However, can you help me in devising a code so as to have it worked on any
specific cells selected instead of only limited for Column A?

"Jacob Skaria" wrote:

Assuming you have data from row1. onwards in .ColA and ColB without headers
try the below macro and feedback

Sub Macro1()

Dim lngRow As Long
Dim lngLastRow As Long
Dim lngTempRow As Long

lngTempRow = 1

lngLastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
For lngRow = 1 To lngLastRow
If Range("A" & lngRow) < "" Then
If lngRow 1 And lngTempRow < lngRow - 1 Then
Range("A" & lngTempRow & ":A" & lngRow - 1).Merge
Range("A" & lngTempRow & ":A" & lngRow - 1).VerticalAlignment = xlCenter
End If
lngTempRow = lngRow
End If
Next
If lngRow 1 And lngTempRow < lngRow - 1 Then
Range("A" & lngTempRow & ":A" & lngRow - 1).Merge
Range("A" & lngTempRow & ":A" & lngRow - 1).VerticalAlignment = xlCenter
End If


End Sub


If this post helps click Yes
---------------
Jacob Skaria


"FARAZ QURESHI" wrote:

I have a list with some blank cells in between. I need to have the entries
appearing at top be merged with the blank cells (if any) below. For example
the table:

BRANCH 1 PRODUCT 1
PRODUCT 2
PRODUCT 7
PRODUCT 3
BRANCH 2 PRODUCT 1
PRODUCT 2
PRODUCT 6
PRODUCT 3
BRANCH 3 PRODUCT 4
BRANCH 4 PRODUCT 5
BRANCH 5 PRODUCT 1
PRODUCT 2
PRODUCT 6
PRODUCT 3

be redesigned as with the branch names to be merged only against their
relative PRODUCTS. Do NOTE that Branch 3 & 4 have no empty cell beneath it
and consist only one product.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing and merging Excel files by using a macro ericlbt Excel Discussion (Misc queries) 4 May 6th 09 06:59 PM
need urgent help on macro merging deepika :excel help[_2_] Excel Discussion (Misc queries) 3 February 27th 08 05:07 AM
Help with Worksheet Merging Macro Joe[_9_] New Users to Excel 13 January 21st 08 12:23 AM
Merging adjacent repeated columns with a macro [email protected] Excel Discussion (Misc queries) 2 April 3rd 07 07:44 PM
Keep Format After Merging Worksheets Using CopyFromWorksheet Macro Mark Jackson Excel Discussion (Misc queries) 0 September 25th 05 10:59 PM


All times are GMT +1. The time now is 03:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"