Hi Tom,
Thanks for the code. It works fine except there are trailing commas at the end of each cell. Like 1,2,,,,,,,, 1,2,3,4,,,,,,,,,,,, etc.
It needs to be 1,2 and 1,2,3,4 etc
Any clues to eliminate these, otherwise ok.
Also while thinking about it, I've used your original code slightly amended to run 3 times from a macro and this works also. The only down side is that it is not automatic but needs to be run from a macro button, but it does the job. Here it is, slightly modified from your original. If you can see any need to amend it please mail back. I'll wait to see though whether the trailing commas can be eliminated to decide which is the best option to use. I like all the input you guys put forward but at the end of the day, I try and use code I can understand.
This is what I have working now.
Sub ConvertAF()
With Application
.Volatile
.ScreenUpdating = 0
Dim LR&, strNum$, cell As Range
LR = Cells(Rows.Count, 32).End(xlUp).Row
strNum = ""
For Each cell In Range("Af8:Af" & LR)
If Len(cell.Value) > 0 Then _
strNum = strNum & cell.Value & ","
Next cell
Range("Af5").Value = Mid(strNum, 1, Len(strNum) - 1)
.ScreenUpdating = 1
End With
Call ConvertAG
Call ConvertAH
End Sub
Sub ConvertAG()
With Application
.Volatile
.ScreenUpdating = 0
Dim LR&, strNum$, cell As Range
LR = Cells(Rows.Count, 33).End(xlUp).Row
strNum = ""
For Each cell In Range("AG8:AG" & LR)
If Len(cell.Value) > 0 Then _
strNum = strNum & cell.Value & ","
Next cell
Range("AG5").Value = Mid(strNum, 1, Len(strNum) - 1)
.ScreenUpdating = 1
End With
End Sub
Sub ConvertAH()
With Application
.Volatile
.ScreenUpdating = 0
Dim LR&, strNum$, cell As Range
LR = Cells(Rows.Count, 34).End(xlUp).Row
strNum = ""
For Each cell In Range("AH8:AH" & LR)
If Len(cell.Value) > 0 Then _
strNum = strNum & cell.Value & ","
Next cell
Range("AH5").Value = Mid(strNum, 1, Len(strNum) - 1)
.ScreenUpdating = 1
End With
End Sub
Cheers for now and thanks Tom
RC
Tom Urtis said:
In that case, substitute the code I posted in Step #3 to this:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("AF8:AH" & Cells.Rows.Count)) Is Nothing Then Exit Sub
Application.ScreenUpdating = 0
Dim i%, LR&, strNum$, cell As Range
For i = 32 To 34
LR = Cells(Rows.Count, i).End(xlUp).Row
If LR < 8 Then
Cells(5, i).ClearContents
Else
strNum = ""
For Each cell In Range(Cells(8, i), Cells(LR, i)).SpecialCells(2)
strNum = strNum & cell.Value & ","
Next cell
Cells(5, i).Value = Mid(strNum, 1, Len(strNum) - 1)
End If
Next i
Application.ScreenUpdating = 1
End Sub
Again, it goes into the sheet module, so follow those steps in #3 for that, and be sure to delete all the other code I posted that you may have copied.