filter active column

NickYOW

New Member
Joined
Mar 5, 2021
Messages
23
Office Version
  1. 2010
Platform
  1. Windows
I am attempting to filter out blank cells of an active column which has 172 rows.
The code need to work across all columns as it transferring the info to another sheet as part of a backup,

please see code below.

Dim col as String
Dim originalsheet as String
Dim lastrow as String
Dim erow as long

originalsheet = " Master Role Profile"
col = split(ActiveCell.Address(1,0), "$")(0)

lastrow = sheets(originalsheet).Cells.SpecialCells(xlCellTypeLastCell).row

sheets(originalsheet).Range(col).AutoFilter field:= col , Criterial1:="<>" I'm receiving error Run-time error 1004 application defined or object defined error

This part works for the copy and past for back up, but takes a long time to go through all 164 cells, this why I would like to filter out the Blanks prior to the to the copy and paste.

For i = 8 to lastrow
erow= Sheets(originalsheet)Cells(1,col).row
sheets(originalsheet).past destination:=Sheets(backup).Cells(erow,col)
next i
Application.CutCopyMode = False
Sheets(originalsheet).ShowAllData
Sheets(originalsheet).autofiltermode = False

looking for some assistance.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
To filter on the active column you can just use
VBA Code:
   ActiveCell.EntireColumn.AutoFilter 1, "<>"
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
To filter on the active column you can just use
VBA Code:
   ActiveCell.EntireColumn.AutoFilter 1, "<>"
You're welcome & thanks for the feedback.
let me know if I have new ask new questions, the code will work as along as I dont have any other filter options or tables and it will put the filter in row 1. I would like to the filter to start on Row 7 instead of the entire column now. would I change Entirecolumn to be my Range(col & " " & 7)
 
Upvote 0
How about
VBA Code:
      Cells(7, ActiveCell.Column).AutoFilter ActiveCell.Column, "<>"
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,089
Members
448,548
Latest member
harryls

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