VBA Macro to select area not working

Browneh89

Board Regular
Joined
Mar 8, 2019
Messages
55
Office Version
  1. 365
Platform
  1. Windows
Hello all!

I'm having a little trouble with a macro I am attempting to record. The macro is supposed to filter a table of data (removing all blanks rows) then select an area in prep to print. when I record the macro I use Ctrl + Shift + arrow key to select the area which I have used before to write a similar macro (which works perfectly) however this time it won't select past the coloums which filter the data. Does anyone know what could be causing this?

Example of the macro that's failing below;

Sub Macro4()
'
' Macro4 Macro
'

'
ActiveSheet.Range("$B$4:$V$99").AutoFilter Field:=5, Criteria1:="<>"
Range("O1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlToLeft)).Select
End Sub

Thank you in advance for any help you can offer!
 
Thank you mate this worked perfectly!! Do you know why my original macro did not work?
IIt is the way Excel is designed to work. While it looks like you are doing the same thing you did in another file, the content of the sheet in in this file is most likely different and you are getting a different result. That is why it is better to use direct coding as opposed to the Select and Activate method.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,215,523
Messages
6,125,320
Members
449,218
Latest member
Excel Master

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