Hi wizards!
I've put together a macro that turns rows containing more than one case in a single cell into separate rows: Say I have "banana, apple, strawberry, cherry" (i.e. 4 cases of fruit) in one single cell and want each case in separate rows in one and the same column. Simple transposing is not an option (I guess) as my sheet have many columns and thousands of rows with a variety of multiple cases in single cells. (If this may be a reason.)
Anyway, I've put together this macro and it works fine apart from:
-> crashing when finished; reaching the end of the column, i.e. at row 65536. Anyway, that's my assessment.
I'd appreciate help on this. I've tried other looping solutions without success. Seems like the Cells.Find procedure is to blame, but I'm at swim.
I'd also like to solve the counting of case separators otherwise than I have managed to: insert a column with a function I found here on the board.
Any help appreciated!
Any other improvements as well 
Thanks in advance!
This is the code:
I've put together a macro that turns rows containing more than one case in a single cell into separate rows: Say I have "banana, apple, strawberry, cherry" (i.e. 4 cases of fruit) in one single cell and want each case in separate rows in one and the same column. Simple transposing is not an option (I guess) as my sheet have many columns and thousands of rows with a variety of multiple cases in single cells. (If this may be a reason.)
Anyway, I've put together this macro and it works fine apart from:
-> crashing when finished; reaching the end of the column, i.e. at row 65536. Anyway, that's my assessment.
I'd appreciate help on this. I've tried other looping solutions without success. Seems like the Cells.Find procedure is to blame, but I'm at swim.
I'd also like to solve the counting of case separators otherwise than I have managed to: insert a column with a function I found here on the board.
Any help appreciated!


Thanks in advance!

This is the code:
Rich (BB code):
Option Explicit
Sub CombinedCasesSplit()
Dim Cell As Range
Dim i As Integer
Dim NOCaseSep As Integer 'number of case separators
Dim nCase As Integer 'number of cases/rows
Dim CaseSep As String
CaseSep = ","
For Each Cell In Range("K:K")
'Find cells with caseseparator:
Cells.Find(What:=CaseSep, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
'Function to return number of caseseparators (here commas) in the cell
' Paste this formula into the "NOCaseSeparators" column (L):
'ActiveCell.Offset(0,1) = SUMMERPRODUKT(--(LENGDE(K2)-LENGDE(BYTT.UT(K2;CaseSep;""))))
'CaseSep = ","
'-Norwegian version of = SUMPRODUCT(--(LEN(K2)-LEN(SUBSTITUTE(K2,CaseSep,""))))
'see http://www.probabilityof.com/excel.shtml#30
'-- How to do this without using the extra column (L),
'i.e. how count the case separators in this sub?
'//----Copy the row NOCaseSep times below Active row
NOCaseSep = ActiveCell.Offset(0, 1)
If NOCaseSep > 0 Then 'ActiveCell.Offset(0, 1) is number of rows /case separators
For i = 1 To ActiveCell.Offset(0, 1)
ActiveCell.Offset(1).EntireRow.Insert
Rows(ActiveCell.Row).Copy
Rows(ActiveCell.Row).Offset(1).PasteSpecial Paste:=xlPasteAll, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Next i
'Select first of the k-column cells to be "cleaned":
ActiveCell.Offset(-NOCaseSep, 10).Activate
End If
'//----"Clean" combined cases:
'1st CASE/ROW:
'keep string left of first case separator:
ActiveCell _
= Mid(ActiveCell, 1, InStr(1, ActiveCell, CaseSep) - 1)
'2nd to penultimate CASE/ROW:
For nCase = NOCaseSep - 1 To 1 Step -1
'remove what is left of NOCaseSep-1'th case separator:
For i = 1 To NOCaseSep - nCase
ActiveCell.Offset(NOCaseSep - nCase, 0) _
= Mid(ActiveCell.Offset(NOCaseSep - nCase, 0), InStr(1, ActiveCell.Offset(NOCaseSep - nCase, 0), CaseSep) + 1, 255)
Next i
'remove what is right of NOCaseSep'th (last) case separator:
ActiveCell.Offset(NOCaseSep - nCase, 0) _
= Mid(ActiveCell.Offset(NOCaseSep - nCase, 0), 1, InStr(1, ActiveCell.Offset(NOCaseSep - nCase, 0), CaseSep) - 1)
Next nCase
'ultimate/last CASE/ROW:
'remove what is left of last case separator:
For i = 1 To NOCaseSep
ActiveCell.Offset(NOCaseSep, 0) _
= Mid(ActiveCell.Offset(NOCaseSep, 0), InStr(1, ActiveCell.Offset(NOCaseSep, 0), CaseSep) + 1, 255)
Next i
Next Cell
End Sub