ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Merging rows- urgent help req (https://www.excelbanter.com/excel-discussion-misc-queries/177500-merging-rows-urgent-help-req.html)

deepika :excel help[_2_]

Merging rows- urgent help req
 
How do i correctt he following code for merging rows of columns A1 which has
the same value.. foreg., teh column is sorted. Now if i have 3 names aclled
A, i should mak ethem as one A and when i reach teh next row with another
name B it shouls check till where teh name B is and should merge the entire B
into one B . Is it possible thru teh following code. i have given 2 codes ,
both don work Pls rectify.. Thank you for any help provided in advance.



Sub merge()
Dim i As Long, j As Long
Selection = RAnge ("A1:A1000")
For i = 3 To Selection.Areas.Count
For j = 3 To Selection.Areas(i).Rows.Count
Application.DisplayAlerts = False
Selection.Areas(i).Rows(j).MergeCells = True
Next
Next

End Sub



( or)


Name = "A"
st = i
en = i
for i = 3 to 1000
If (Name = Sheets("FTP").Cells(i, 1).Value) Then
Range("A" &st& ":Je" &en).Merge
name = Sheets("FTP").Cells(i+1, 2).Value

Else
st = i + 1
en = i
End If



deepika :excel help[_2_]

Merging rows- urgent help req
 
or pls correct the following code for me
This code should search in col B for same names and merge it . But my code
is searching only for teh name A and merging it... the names below it are not
getting merged.. what shud i write in the else part or how shud i proceed


Sub merge()

en = 3

For i = 1 To 1000
If Cells(i, 2).Value = "A" Then
Range("B" & i & ":B" & en + 1).merge
End If

i = i + 1
en = i
Next


End Sub






"deepika :excel help" wrote:

How do i correctt he following code for merging rows of columns A1 which has
the same value.. foreg., teh column is sorted. Now if i have 3 names aclled
A, i should mak ethem as one A and when i reach teh next row with another
name B it shouls check till where teh name B is and should merge the entire B
into one B . Is it possible thru teh following code. i have given 2 codes ,
both don work Pls rectify.. Thank you for any help provided in advance.



Sub merge()
Dim i As Long, j As Long
Selection = RAnge ("A1:A1000")
For i = 3 To Selection.Areas.Count
For j = 3 To Selection.Areas(i).Rows.Count
Application.DisplayAlerts = False
Selection.Areas(i).Rows(j).MergeCells = True
Next
Next

End Sub



( or)


Name = "A"
st = i
en = i
for i = 3 to 1000
If (Name = Sheets("FTP").Cells(i, 1).Value) Then
Range("A" &st& ":Je" &en).Merge
name = Sheets("FTP").Cells(i+1, 2).Value

Else
st = i + 1
en = i
End If



John Bundy

Merging rows- urgent help req
 
A couple things that look wrong here
en = 3

For i = 1 To 1000
If Cells(i, 2).Value = "A" Then
Range("B" & i & ":B" & en + 1).merge
End If

i = i + 1
en = i
Next
First you have en=3 so it will merge the first time B1 to B4 (en+1=4)
then later you set en to i, so the second loop would merge B2 to B3
finally you are doubling up i, i already increments one automatically when
it gets to the Next, you are adding i+1 and then the Next adds another one,
so you are actually only checking every other row. Hope that steers you in
the right direction.
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"deepika :excel help" wrote:

or pls correct the following code for me
This code should search in col B for same names and merge it . But my code
is searching only for teh name A and merging it... the names below it are not
getting merged.. what shud i write in the else part or how shud i proceed


Sub merge()

en = 3

For i = 1 To 1000
If Cells(i, 2).Value = "A" Then
Range("B" & i & ":B" & en + 1).merge
End If

i = i + 1
en = i
Next


End Sub






"deepika :excel help" wrote:

How do i correctt he following code for merging rows of columns A1 which has
the same value.. foreg., teh column is sorted. Now if i have 3 names aclled
A, i should mak ethem as one A and when i reach teh next row with another
name B it shouls check till where teh name B is and should merge the entire B
into one B . Is it possible thru teh following code. i have given 2 codes ,
both don work Pls rectify.. Thank you for any help provided in advance.



Sub merge()
Dim i As Long, j As Long
Selection = RAnge ("A1:A1000")
For i = 3 To Selection.Areas.Count
For j = 3 To Selection.Areas(i).Rows.Count
Application.DisplayAlerts = False
Selection.Areas(i).Rows(j).MergeCells = True
Next
Next

End Sub



( or)


Name = "A"
st = i
en = i
for i = 3 to 1000
If (Name = Sheets("FTP").Cells(i, 1).Value) Then
Range("A" &st& ":Je" &en).Merge
name = Sheets("FTP").Cells(i+1, 2).Value

Else
st = i + 1
en = i
End If




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com