VBA working through subtotal fall overs when only one of of text on last subtotal

grapevine

Board Regular
Joined
May 23, 2007
Messages
208
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
Code:
ActiveCell.End(xlDown).Offset(1, 0).Select
Many thanks
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
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I am managed to sort, for some reason i had an extra line of code which was causing the problem - I did not need this line of code

Code:
' move active cell to new place on worksheet
            ActiveCell.Offset(2, 0).Activate
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top