loop help

justme1122

New Member
Joined
Mar 6, 2011
Messages
47
Hi IOm having a little trouble with the below code.

Debug is show that Im getting stuck at:

PHP:
Loop Until Found.Row = Lastrow

PHP:
Sub Shift_Data()
    Dim Found As Range, col As Long, Lastrow As Long
    Dim ws As Worksheet
    
    Application.ScreenUpdating = False
    For Each ws In Worksheets
        col = 1
        Set Found = ws.Columns(col).Find("SubTotal", , xlValues, xlWhole, xlByRows, xlNext, False)
        If Not Found Is Nothing Then
            Lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row
            If Found.Row <> Lastrow Then
                Do
                    ws.Range(Found.Offset(1), ws.Cells(Lastrow, col)).Insert Shift:=xlToRight
                    col = col + 1
                    Set Found = ws.Columns(col).Find("SubTotal")
                Loop Until Found.Row = Lastrow
            End If
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub

Im also having a bit of trouble setting up another loop that will make the code select the next worksheet and then do the same thing over and over untill the last work sheet.

Thanks
So much for your time

scott
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Scott

I think you need FindNext the instead of Find in the row just before that.
 
Upvote 0
thanks but still no luck.

Could it be posible that its having a hard time finding the last row as there is other data under the last time for the loop?
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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