VBA Selection Macro

amattey

New Member
Joined
Jul 18, 2011
Messages
46
Hi,

I am writing a macro that will filter the data from one workbook sheet, and past it into another workbooks sheet. After the data is filter I want to copy just the filtered data from columns F,G,H as code below, but it does not work. Is there anything missing I should consider? Will much appreciate the help..

Code:
ActiveSheet.Range("$A$1:$AC$1654").AutoFilter Field:=1, Criteria1:="PCM"
ActiveSheet.Range("$A$1:$AC$1654").AutoFilter Field:=3, Criteria1:="N"
Columns("F:H").Offset(1, 0).Select
Selection.Copy
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Like this:

Code:
Sub shortercode()

With Range("A1:AC1654")
    .AutoFilter Field:=1, Criteria1:="PCM"
    .AutoFilter Field:=3, Criteria1:="N"
    .Columns("F:H").Offset(1).SpecialCells(xlCellTypeVisible).Copy
End With

End Sub
 
Upvote 0
I think you're going to have a problem with this because of the

.columns("F:H").offset(1)

part, since it's trying to define a range that goes 1 row further than the total size of the sheet.

Try something like

Code:
Sub shortercode()
With Range("A1:AC1654")
    .AutoFilter Field:=1, Criteria1:="PCM"
    .AutoFilter Field:=3, Criteria1:="N"
    .Columns("F:H").Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy
End With
End Sub
 
Upvote 0
Weaver,

I do not know if you tested it, but can you please run:

Code:
Sub shortercode()

MsgBox Range("A1:AC1654").Columns("F:H").Offset(1).Address

End Sub
 
Upvote 0
Wigi it does work. I had another question, I have 3 columns in one sheet, The first one is a date formated (mm,dd,yyyy), the second one is an output column, and the third one is the input. I wanted to create a formula that will select whatever is in the third column as the input and if column 1 is 1 year less or 2 years after a date that is located in another ceel (different sheet), to say something like "Do this year". Could you advise in how to get started, I wrote something but even I looking at it does not make much sense.
 
Upvote 0
Please start a different topic.
The current topic is solved, and has a different subject than your new question.
 
Upvote 0
Weaver,

I do not know if you tested it, but can you please run:

Code:
Sub shortercode()
 
MsgBox Range("A1:AC1654").Columns("F:H").Offset(1).Address
 
End Sub
Apologies - my bad, the code I was testing with didn't initially have a range, so I was working with the entire column
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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