copy row to new workbook if a cell is 0.1 or less

rooster05

New Member
Joined
Mar 4, 2017
Messages
34
hello

i have a workbook titled 3 months and in this wb i have Sheet1 which contains data i need copying to a new wb if cell in column D is 0.1 or less, this could be 1 or 200 rows. this new wb would need to be saved in a different filepath. i'm assuming this is possible but i am not sure how to do it any help would be greatly appreciated
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hello Rooster,

Without knowing all the details of your sheet, this is my first guess at what might work. Just remember to change the filepath/filename at the end of the code!

Code:
Sub FindandSave()
    Dim wb As Workbook, wbNew As Workbook
    Dim i As Integer, j As Integer
    Dim arr() As Variant
    
    Application.ScreenUpdating = False
    Set wb = ActiveWorkbook
    Set wbNew = Workbooks.Add
    j = 1
    With wb.Sheets("Sheet1")
        For i = 1 To 200
            If .Range("D" & i).Value <= 0.1 Then
                .Rows(i).Copy wbNew.Sheets("Sheet1").Rows(j)
                j = j + 1
            End If
        Next i
    End With
    Application.ScreenUpdating = True
    wbNew.SaveAs "C:\Users\Name\Desktop\Filename.xls"
End Sub

Hope that helps
Caleeco
 
Upvote 0
Caleeco,

that is perfect and works a treat.
as an addition to this would i be able to copy the headers too
 
Upvote 0
Hi Rooster,

Ok that's great, thanks for letting me know it worked! Yes, i can modify it slightly as shown below (assumes headers are in row 1)
Code:
Sub FindandSave()
    Dim wb As Workbook, wbNew As Workbook
    Dim i As Integer, j As Integer
    Dim arr() As Variant
    
    Application.ScreenUpdating = False
    Set wb = ActiveWorkbook
    Set wbNew = Workbooks.Add
    j = 2
    With wb.Sheets("Sheet1")
        .Rows(1).Copy wbNew.Sheets("Sheet1").Rows(1)
        For i = 1 To 200
            If .Range("D" & i).Value <= 0.1 Then
                .Rows(i).Copy wbNew.Sheets("Sheet1").Rows(j)
                j = j + 1
            End If
        Next i
    End With
    Application.ScreenUpdating = True
    wbNew.SaveAs "C:\Users\Name\Desktop\Filename.xls"
End Sub

Hope that helps
Caleeco
 
Upvote 0
Just a different method to try just as I was bored...

Rich (BB code):
Sub FindandSave()
    Dim wb As Workbook, wbNew As Workbook

    Application.ScreenUpdating = False
    Set wb = ActiveWorkbook
    Set wbNew = Workbooks.Add

    With wb.Sheets("Sheet1").Range("D1:D200")
        .AutoFilter 1, "<0.1"
        On Error Resume Next
        .SpecialCells(12).EntireRow.Copy wbNew.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp)(2)
        On Error GoTo 0
        .AutoFilter
    End With
    
    wbNew.Sheets("Sheet1").Rows(1).Delete
    Application.ScreenUpdating = True
    wbNew.SaveAs "C:\Users\Name\Desktop\Filename.xls"
End Sub
 
Last edited:
Upvote 0
Caleeco / Mark858,

thanks for replying so quick, i'm unable to apply these at the moment. i have one question (sorry), apologies for not asking at the outset if i were to change the copy part to cut how could this be done without removing the headers. apologies again
 
Upvote 0
With mine it's easier just to delete the range rather than use cut.

Rich (BB code):
Sub FindandSave()
    Dim wb As Workbook, wbNew As Workbook

    Application.ScreenUpdating = False
    Set wb = ActiveWorkbook
    Set wbNew = Workbooks.Add

    With wb.Sheets("Sheet1").Range("D1:D200")
        .AutoFilter 1, "<0.1"
        On Error Resume Next
        .SpecialCells(12).EntireRow.Copy wbNew.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp)(2)
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).EntireRow.Delete
        On Error GoTo 0
        .AutoFilter
    End With

    wbNew.Sheets("Sheet1").Rows(1).Delete
    Application.ScreenUpdating = True
    wbNew.SaveAs "C:\Users\Name\Desktop\Filename.xls"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,193
Members
452,616
Latest member
intern444

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