filter active column

NickYOW

New Member
Joined
Mar 5, 2021
Messages
21
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 did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,545
Office Version
  1. 365
Platform
  1. Windows
To filter on the active column you can just use
VBA Code:
   ActiveCell.EntireColumn.AutoFilter 1, "<>"
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,545
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

NickYOW

New Member
Joined
Mar 5, 2021
Messages
21
Office Version
  1. 2010
Platform
  1. Windows

ADVERTISEMENT

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)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,545
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
      Cells(7, ActiveCell.Column).AutoFilter ActiveCell.Column, "<>"
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,545
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,129,515
Messages
5,636,793
Members
416,941
Latest member
shazzaxyz

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
Top