Alex O
Active Member
- Joined
- Mar 16, 2009
- Messages
- 345
- Office Version
- 365
- Platform
- Windows
I'm stuck trying to figure out one minor error with the macro below. For some reason each new string begins with the last entry from the previous row (see example column AA). Can anyone identify what the source of the error might be?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
Thanks,<o></o>
Sub ConcatDataV1()
Dim LR As Long, LR2 As Long, a As Long, aa As Long, SR As Long, ER As Long, H As String
Application.ScreenUpdating = False
LR = Cells(Rows.Count, "B").End(xlUp).Row
Range("Z3:AC" & LR).ClearContents
Range("B3:B" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("Z3"), Unique:=True
Range("Z3").ClearContents
LR2 = Cells(Rows.Count, "Z").End(xlUp).Row
Range("AB4").Formula = "=MATCH(Z4,B:B,0)"
Range("AB4").AutoFill Destination:=Range("AB4:AB" & LR2)
Range("AC4").Formula = "=AB6-1"
Range("AC4").AutoFill Destination:=Range("AC4:AC" & LR2 - 1)
Range("AC" & LR2) = LR
For a = 5 To LR2 Step 1
SR = Range("AB" & a).Value
ER = Range("AC" & a).Value
H = ""
For aa = SR To ER Step 1
H = H & Cells(aa, "Y") & ", "
Next aa
If Right(H, 2) = ", " Then H = Left(H, Len(H) - 2)
Range("AA" & a) = H
Next a
Range("AB4:AC" & LR2).ClearContents
Columns("Z:AA").AutoFit
Range("Z4").Select
Application.ScreenUpdating = True
End Sub
<TABLE style="BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 2pt; PADDING-RIGHT: 2pt; FONT-FAMILY: Calibri,Arial; FONT-SIZE: 11pt" border=1 cellSpacing=0 cellPadding=0><COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 72px"><COL style="WIDTH: 249px"><COL style="WIDTH: 114px"><COL style="WIDTH: 84px"><COL style="WIDTH: 67px"><COL style="WIDTH: 85px"><COL style="WIDTH: 104px"><COL style="WIDTH: 68px"><COL style="WIDTH: 66px"><COL style="WIDTH: 83px"><COL style="WIDTH: 68px"><COL style="WIDTH: 144px"><COL style="WIDTH: 85px"><COL style="WIDTH: 161px"><COL style="WIDTH: 370px"><COL style="WIDTH: 249px"></COLGROUP><TBODY><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt; FONT-WEIGHT: bold"><TD></TD><TD>L</TD><TD>M</TD><TD>N</TD><TD>O</TD><TD>P</TD><TD>Q</TD><TD>R</TD><TD>S</TD><TD>T</TD><TD>U</TD><TD>V</TD><TD>W</TD><TD>X</TD><TD>Y</TD><TD>Z</TD><TD>AA</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">4</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ff99cc">STAN/10</TD><TD style="TEXT-ALIGN: left">STANISLAUS</TD><TD style="TEXT-ALIGN: left">962217</TD><TD style="TEXT-ALIGN: left">11/13/2009</TD><TD style="TEXT-ALIGN: left">2613.6</TD><TD style="TEXT-ALIGN: left">916.05</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ff99cc">916.05</TD><TD style="TEXT-ALIGN: left">7/20/2011</TD><TD style="TEXT-ALIGN: left">916.05</TD><TD style="TEXT-ALIGN: left">25</TD><TD style="TEXT-ALIGN: left">WO-DEL</TD><TD style="TEXT-ALIGN: left">JOHN W VILLINES</TD><TD style="TEXT-ALIGN: left">262.65</TD><TD style="TEXT-ALIGN: left">STAN/10-916.05</TD><TD style="TEXT-ALIGN: left">JV LAW</TD><TD></TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">5</TD><TD style="TEXT-ALIGN: left">STAN/11</TD><TD style="TEXT-ALIGN: left">STANISLAUS</TD><TD style="TEXT-ALIGN: left">1020857</TD><TD style="TEXT-ALIGN: left">9/29/2010</TD><TD style="TEXT-ALIGN: left">3162.48</TD><TD style="TEXT-ALIGN: left">3393.8</TD><TD style="TEXT-ALIGN: left">3393.8</TD><TD style="TEXT-ALIGN: left">7/20/2011</TD><TD style="TEXT-ALIGN: left">3393.8</TD><TD style="TEXT-ALIGN: left">25</TD><TD style="TEXT-ALIGN: left">WO-DEL</TD><TD style="TEXT-ALIGN: left">JOHN W VILLINES</TD><TD style="TEXT-ALIGN: left">231.32</TD><TD style="TEXT-ALIGN: left">STAN/11-3393.8</TD><TD style="TEXT-ALIGN: left">JAIME E VILLAGRANA CABINET MAKERS</TD><TD>YUBA/09-1082.57, YUBA/10-944.05</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">6</TD><TD style="TEXT-ALIGN: left">YUBA/09</TD><TD style="TEXT-ALIGN: left">YUBA & SUTTER COUNTIES</TD><TD style="TEXT-ALIGN: left">897015</TD><TD style="TEXT-ALIGN: left">11/21/2008</TD><TD style="TEXT-ALIGN: left">1584</TD><TD style="TEXT-ALIGN: left">1082.57</TD><TD style="TEXT-ALIGN: left">1082.57</TD><TD style="TEXT-ALIGN: left">7/21/2011</TD><TD style="TEXT-ALIGN: left">1082.57</TD><TD style="TEXT-ALIGN: left">25</TD><TD style="TEXT-ALIGN: left">WO-DEL</TD><TD style="TEXT-ALIGN: left">JAIME VILLAGRANA</TD><TD style="TEXT-ALIGN: left">242.01</TD><TD style="TEXT-ALIGN: left">YUBA/09-1082.57</TD><TD style="TEXT-ALIGN: left">BRANDON BROWN</TD><TD>YUBA/10-944.05, SANL/10-1355.81</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">7</TD><TD style="TEXT-ALIGN: left">YUBA/10</TD><TD style="TEXT-ALIGN: left">YUBA & SUTTER COUNTIES</TD><TD style="TEXT-ALIGN: left">969534</TD><TD style="TEXT-ALIGN: left">1/8/2010</TD><TD style="TEXT-ALIGN: left">1729.2</TD><TD style="TEXT-ALIGN: left">944.05</TD><TD style="TEXT-ALIGN: left">944.05</TD><TD style="TEXT-ALIGN: left">7/21/2011</TD><TD style="TEXT-ALIGN: left">944.05</TD><TD style="TEXT-ALIGN: left">25</TD><TD style="TEXT-ALIGN: left">WO-DEL</TD><TD style="TEXT-ALIGN: left">BRANDON BROWN</TD><TD style="TEXT-ALIGN: left">157.73</TD><TD style="TEXT-ALIGN: left">YUBA/10-944.05</TD><TD style="TEXT-ALIGN: left">TAHLIA'S CUCINA</TD><TD>SANL/10-1355.81, LALH/10-1673.41</TD></TR></TBODY></TABLE>
Thanks,<o></o>
Sub ConcatDataV1()
Dim LR As Long, LR2 As Long, a As Long, aa As Long, SR As Long, ER As Long, H As String
Application.ScreenUpdating = False
LR = Cells(Rows.Count, "B").End(xlUp).Row
Range("Z3:AC" & LR).ClearContents
Range("B3:B" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("Z3"), Unique:=True
Range("Z3").ClearContents
LR2 = Cells(Rows.Count, "Z").End(xlUp).Row
Range("AB4").Formula = "=MATCH(Z4,B:B,0)"
Range("AB4").AutoFill Destination:=Range("AB4:AB" & LR2)
Range("AC4").Formula = "=AB6-1"
Range("AC4").AutoFill Destination:=Range("AC4:AC" & LR2 - 1)
Range("AC" & LR2) = LR
For a = 5 To LR2 Step 1
SR = Range("AB" & a).Value
ER = Range("AC" & a).Value
H = ""
For aa = SR To ER Step 1
H = H & Cells(aa, "Y") & ", "
Next aa
If Right(H, 2) = ", " Then H = Left(H, Len(H) - 2)
Range("AA" & a) = H
Next a
Range("AB4:AC" & LR2).ClearContents
Columns("Z:AA").AutoFit
Range("Z4").Select
Application.ScreenUpdating = True
End Sub
<TABLE style="BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 2pt; PADDING-RIGHT: 2pt; FONT-FAMILY: Calibri,Arial; FONT-SIZE: 11pt" border=1 cellSpacing=0 cellPadding=0><COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 72px"><COL style="WIDTH: 249px"><COL style="WIDTH: 114px"><COL style="WIDTH: 84px"><COL style="WIDTH: 67px"><COL style="WIDTH: 85px"><COL style="WIDTH: 104px"><COL style="WIDTH: 68px"><COL style="WIDTH: 66px"><COL style="WIDTH: 83px"><COL style="WIDTH: 68px"><COL style="WIDTH: 144px"><COL style="WIDTH: 85px"><COL style="WIDTH: 161px"><COL style="WIDTH: 370px"><COL style="WIDTH: 249px"></COLGROUP><TBODY><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt; FONT-WEIGHT: bold"><TD></TD><TD>L</TD><TD>M</TD><TD>N</TD><TD>O</TD><TD>P</TD><TD>Q</TD><TD>R</TD><TD>S</TD><TD>T</TD><TD>U</TD><TD>V</TD><TD>W</TD><TD>X</TD><TD>Y</TD><TD>Z</TD><TD>AA</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">4</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ff99cc">STAN/10</TD><TD style="TEXT-ALIGN: left">STANISLAUS</TD><TD style="TEXT-ALIGN: left">962217</TD><TD style="TEXT-ALIGN: left">11/13/2009</TD><TD style="TEXT-ALIGN: left">2613.6</TD><TD style="TEXT-ALIGN: left">916.05</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ff99cc">916.05</TD><TD style="TEXT-ALIGN: left">7/20/2011</TD><TD style="TEXT-ALIGN: left">916.05</TD><TD style="TEXT-ALIGN: left">25</TD><TD style="TEXT-ALIGN: left">WO-DEL</TD><TD style="TEXT-ALIGN: left">JOHN W VILLINES</TD><TD style="TEXT-ALIGN: left">262.65</TD><TD style="TEXT-ALIGN: left">STAN/10-916.05</TD><TD style="TEXT-ALIGN: left">JV LAW</TD><TD></TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">5</TD><TD style="TEXT-ALIGN: left">STAN/11</TD><TD style="TEXT-ALIGN: left">STANISLAUS</TD><TD style="TEXT-ALIGN: left">1020857</TD><TD style="TEXT-ALIGN: left">9/29/2010</TD><TD style="TEXT-ALIGN: left">3162.48</TD><TD style="TEXT-ALIGN: left">3393.8</TD><TD style="TEXT-ALIGN: left">3393.8</TD><TD style="TEXT-ALIGN: left">7/20/2011</TD><TD style="TEXT-ALIGN: left">3393.8</TD><TD style="TEXT-ALIGN: left">25</TD><TD style="TEXT-ALIGN: left">WO-DEL</TD><TD style="TEXT-ALIGN: left">JOHN W VILLINES</TD><TD style="TEXT-ALIGN: left">231.32</TD><TD style="TEXT-ALIGN: left">STAN/11-3393.8</TD><TD style="TEXT-ALIGN: left">JAIME E VILLAGRANA CABINET MAKERS</TD><TD>YUBA/09-1082.57, YUBA/10-944.05</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">6</TD><TD style="TEXT-ALIGN: left">YUBA/09</TD><TD style="TEXT-ALIGN: left">YUBA & SUTTER COUNTIES</TD><TD style="TEXT-ALIGN: left">897015</TD><TD style="TEXT-ALIGN: left">11/21/2008</TD><TD style="TEXT-ALIGN: left">1584</TD><TD style="TEXT-ALIGN: left">1082.57</TD><TD style="TEXT-ALIGN: left">1082.57</TD><TD style="TEXT-ALIGN: left">7/21/2011</TD><TD style="TEXT-ALIGN: left">1082.57</TD><TD style="TEXT-ALIGN: left">25</TD><TD style="TEXT-ALIGN: left">WO-DEL</TD><TD style="TEXT-ALIGN: left">JAIME VILLAGRANA</TD><TD style="TEXT-ALIGN: left">242.01</TD><TD style="TEXT-ALIGN: left">YUBA/09-1082.57</TD><TD style="TEXT-ALIGN: left">BRANDON BROWN</TD><TD>YUBA/10-944.05, SANL/10-1355.81</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">7</TD><TD style="TEXT-ALIGN: left">YUBA/10</TD><TD style="TEXT-ALIGN: left">YUBA & SUTTER COUNTIES</TD><TD style="TEXT-ALIGN: left">969534</TD><TD style="TEXT-ALIGN: left">1/8/2010</TD><TD style="TEXT-ALIGN: left">1729.2</TD><TD style="TEXT-ALIGN: left">944.05</TD><TD style="TEXT-ALIGN: left">944.05</TD><TD style="TEXT-ALIGN: left">7/21/2011</TD><TD style="TEXT-ALIGN: left">944.05</TD><TD style="TEXT-ALIGN: left">25</TD><TD style="TEXT-ALIGN: left">WO-DEL</TD><TD style="TEXT-ALIGN: left">BRANDON BROWN</TD><TD style="TEXT-ALIGN: left">157.73</TD><TD style="TEXT-ALIGN: left">YUBA/10-944.05</TD><TD style="TEXT-ALIGN: left">TAHLIA'S CUCINA</TD><TD>SANL/10-1355.81, LALH/10-1673.41</TD></TR></TBODY></TABLE>