Filter out certain lines before paste (Macro)

Bennyton

New Member
Joined
Apr 13, 2011
Messages
20
Hey all, I'm having a little trouble with a Macro at the moment, I need to copy 4 columns on one page, (A, B, C and D) and paste them into another sheet on Columns C, D, E and F. That I have achieved...

However, I also need to filter out any row where the value of column A begins with a 6. Only if It begins with a 6, it can contain one after that..

I'd like to be able to pull the numbers, filter them, and paste the ones that pass if that would be at all possible.

The following is what I've come up with so far,
but I am still fairly new to this stuff.

Sub orgtowip()
Columns("A:E").Select
Selection.Copy
Sheets("wip").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.Save
End Sub

any help or tips on where to look would be greatly appreciated.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Code:
Sub GetSixths()

    Dim rng As Range
    
    Rows(1).Insert 'Dummy row
    
    With Range("A1:D1")
        .AutoFilter Field:=1, Criteria1:="6"
        Set rng = Range("A2:D" & Cells(Rows.Count, "A").End(xlUp).Row)
        If Not rng Is Nothing Then
            rng.Copy Sheets("AnotherSheet").Range("C1")
        End If
        .AutoFilter 'Remove filter
    End With
    
    Rows(1).Delete 'Delete dummy row

End Sub
 
Upvote 0
Thanks for the reply Sektor!

However, It doesn't seem to filter the values at all,

I've changed the sheet to take the values at column a rather than C

Sub Filter6hundreads()

Dim rng As Range

Rows(1).Insert 'Dummy row

With Range("A1:D1")
.AutoFilter Field:=1, Criteria1:="6"
Set rng = Range("A2:D" & Cells(Rows.Count, "A").End(xlUp).Row)
If Not rng Is Nothing Then
rng.Copy Sheets("wip").Range("A1")
End If
.AutoFilter 'Remove filter
End With

Rows(1).Delete 'Delete dummy row
End Sub

I think this one is looking for simply a 6,however the values are product numbers, and most are 6 chars long with a dash,
and 3 more chars ie 600123-123

I simply want to filter out rows based on the first number of column A only.
 
Upvote 0
Solved it, solution here for anyone looking for it in future.

had to convert column to text and assess the first number with a custom filter, ie begins with.

thanks again sektor ;)


Code:
Sub Filter6hundreads()
    Sheets("wip").Select
    Columns("B:B").Select
    Selection.Delete Shift:=xlToLeft
    Columns("A:A").Select
    Selection.Delete Shift:=xlToLeft
    Range("A1:AA9999").Select
    Selection.ClearContents
    Dim rng As Range
    
    Sheets("original").Select
    
    Rows(1).Insert 'Dummy row
    
    'Formats column A as text so it can be filtered as such,
    Columns("A:A").Select
    Selection.NumberFormat = "@"
    
    'Filters Column A as text to bring through only those part numbers that start with 4
    With Range("A1:D1")
    Selection.AutoFilter
        .AutoFilter Field:=1, Criteria1:="=4*", Operator:=xlAnd
        Set rng = Range("A2:D" & Cells(Rows.Count, "A").End(xlUp).Row)
        If Not rng Is Nothing Then
            rng.Copy Sheets("wip").Range("A2")
            
        End If
        .AutoFilter 'Remove filter
    End With
    
    Rows(1).Delete 'Delete dummy row
    Rows(1).Select
    Selection.Copy
    Sheets("wip").Select
    Range("A1").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveWorkbook.Save
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,740
Messages
6,174,223
Members
452,552
Latest member
Kleets

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