Hello all.

I have the following code. In some cells in the worksheet there is data that is separated with "," for example "kkkkk,ddddd" and I want to separate the data where the "," is found and put each string found to the cells bellow, and copying the remaining row.

The code works fine in the test worksheet. The only change that i did was to change the name of the worksheet. When I run it i always get runtime error 1004 Application-defined or object-defined error when i am trying to insert a new row.

I cant figure out the problem. The only thing that I think it can cause problem is that the button is in a different worksheet than the code is referring to.

Private Sub CommandButton5_Click()
Dim str As String
Dim strarr As Variant
Dim i As Long
Dim rng As Range
Worksheets("Total").Unprotect
For i = 2 To Worksheets("Total").Rows.count
 str = Worksheets("Total").Cells(i, 6)
 If InStr(1, str, ",") > 0 Then
 Set rng = Worksheets("Total").Cells(i, 6).EntireRow
  strarr = Split(str, ",")
  Worksheets("Total").Range(Cells(i + 1, 6), Cells(i + UBound(strarr), 6)).EntireRow.Insert (xlShiftDown)
  For j = 0 To UBound(strarr)
   Worksheets("Total").Cells(j + i, 6).EntireRow.Value = rng.Value
   Worksheets("Total").Rows(j + i).Interior.Color = vbRed
   Worksheets("Total").Cells(j + i, 6) = strarr(j)
  Next j
 End If
 Next i
End Sub