I have the following code - (some sensitive information replaced by the word info) which works fine when each subtotal group has several entries, but falls over when there is only one entry. Could someone please help me out. The part of the code where is it specially giving me the 1004 error is
Many thanks
Code:
ActiveCell.End(xlDown).Offset(1, 0).Select
Code:
For y = 1 To k
If Worksheets(y).Name Like "TM011*" Then
Worksheets(y).Activate
Workbooks(la).Worksheets(y).Range("E8") = Workbooks(la).Worksheets(y).Range("E11")
Workbooks(io).Sheets("TM011").Activate
Range("Q2").Select
Do Until ActiveCell = "Grand Total" Or ActiveCell.Offset(0, -5) = "Grand Total"
If ActiveCell = Workbooks(la).Worksheets(y).Range("E8").Value Then
'insert row and insert required information
Application.CutCopyMode = False
Workbooks(la).Worksheets(y).Range("A11").EntireRow.Insert
Workbooks(la).Worksheets(y).Range("D11") = ActiveCell.End(xlDown).Offset(1, -4)
Workbooks(la).Worksheets(y).Range("N11").Value = "more info " & ActiveCell.Offset(0, -6)
Workbooks(la).Worksheets(y).Range("N11").Copy
Workbooks(la).Worksheets(y).Range("N11").PasteSpecial Paste:=xlPasteValues
Workbooks(la).Worksheets(y).Range("E11").FormulaR1C1 = "=if(R[-4]C[4]=""UK"",R[0]C[9],R[0]C[9] & "" HK "")"
'Workbooks(la).Worksheets(y).Range("E11").FormulaR1C1 = "=if(R[-4]C[4]=""UK"",""info "" & ActiveCell.Offset(0, -6),""info "" & ActiveCell.Offset(0, -6) & "" "")"
Workbooks(la).Worksheets(y).Range("F11") = "info"
Workbooks(la).Worksheets(y).Range("G11").FormulaR1C1 = "=if(R[-4]C[2]=""UK"",""Stock"", ""HBO Stock"")"
Workbooks(la).Worksheets(y).Range("H11") = "XXXX"
Workbooks(la).Worksheets(y).Range("L1").Clear
Workbooks(la).Worksheets(y).Range("I11").FormulaR1C1 = "=IF(ISERROR(VLOOKUP(R[-7]C[0],labelcodes,7,FALSE)),""unknown description"",VLOOKUP(R[-7]C[0],labelcodes,7,FALSE))"
Workbooks(la).Worksheets(y).Range("I11").Value = Workbooks(la).Worksheets(y).Range("I11").Value
' move active cell to new place on worksheet
ActiveCell.Offset(2, 0).Activate
End If
ActiveCell.End(xlDown).Offset(1, 0).Select ' this is the line that the macro is falling over at
If ActiveCell = "" Then
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell Like "Grand Total" Then
GoTo skip 'ActiveCell.Select
ElseIf ActiveCell Like "*Total" Then
ActiveCell.Offset(1, 0).Select
End If
skip:
Loop