
Originally Posted by
sintek
So why not simply...
Sintek,
There are actually 2 problems with the code. The first is that it clears the following column to the right. It's not a big deal as I can paste it from the original sample. The other problem is whenever I run your macro to replace the codes, I can't run another macro that concatenates the values on column M and N. This other macro works fine with the SKU numbers, and was working fine with the first macro I posted that took hours. I've been checking for hours for any difference between the original sheet and the sheet after running your macro, but I can't find anything different.
When I run this code below, I get a Run Time Error 9 Subscript Out of Range.
Sub findconcat_samecells_arr2()
Dim cel, fr As Range
Dim k, g, ofst, lr, frr As Long
Dim i, j As Long
Dim a()
Application.ScreenUpdating = False
Columns("M:M").NumberFormat = "@"
Range("M18:N" & Cells(Rows.Count, 1).End(xlUp).Row).ClearContents
a = Range(Cells(1, 1), Cells(Cells(Rows.Count, 2).End(xlUp).Row + 1, 14))
For i = LBound(a) To UBound(a)
If a(i, 6) Like "???[.]???[.]???[-]??" Then
For j = i To UBound(a)
If InStr(a(j, 1), "digo") > 1 Then
frr = j '20
GoTo Nxt
End If
Next j
Nxt:
On Error Resume Next
ofst = Range(Cells(i, 1), Cells(frr, 1)).SpecialCells(xlCellTypeBlanks).Count
If ofst Is Nothing Then
ofst = 0
End If
On Error GoTo 0
k = 1 + ofst
Do While Not IsEmpty(a(j + k, 1))
If InStr(a(j + k, 1), "digo") < 1 Then
Cells(i, 13).Value = Cells(i, 13).Value & ", " & a(j + k, 1)
End If
k = k + 1
Loop
g = 0
Do While Not IsEmpty(a(i + g, 7))
If g = 0 Then
a(i, 14) = a(i + g, 7)
Else
a(i, 14) = a(i + g, 7) & "," & a(i, 14)
End If
Cells(i, 14).Value = a(i, 14)
g = g + 1
Loop
End If
Next i
Application.ScreenUpdating = True
End Sub
Any idea what could be causing the problem?
EDIT: The code above concatenates all values into a single cell, instead of working and supposed: counting the blanks and the text "Código" to determine a group of data that belongs to a single customer ID. I'm not sure how this helps, but the info might be useful
Bookmarks