Filter - function

denton

New Member
Joined
Oct 17, 2006
Messages
20
I have some cells in column A filled with numbers and some are empty->eg. in A1 is number, A2 number, A3 empty,A4 empty,A5 number,A6 empty etc.
I need some function to collect only not empty cells in column A and write those cells to another column. So in C1 is number from A1,C2->A2,C3->A5. Can anyone help me?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,958
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Hi

1. apply an Autofilter to the range.
2. filter the nonblanks (i.e. after left clicking the down triangle appearing)
3. select the filtered cells, and do a normal Copy and then Paste where you want the data.

Wigi
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,454
Hello denton, welcome to the board.
For a quick little macro to do what wigi is suggesting:
Code:
Sub Demo()
With Application
  .ScreenUpdating = False
  With Columns("A:A")
    .AutoFilter Field:=1, Criteria1:="<>"
    .Copy Range("C1")
  End With
  ActiveSheet.AutoFilterMode = False
  .CutCopyMode = False
  .ScreenUpdating = True
End With
End Sub
 

denton

New Member
Joined
Oct 17, 2006
Messages
20
Hi

1. apply an Autofilter to the range.
2. filter the nonblanks (i.e. after left clicking the down triangle appearing)
3. select the filtered cells, and do a normal Copy and then Paste where you want the data.

Wigi

but...if i do this, it will copy only first block of non empty cells, not all filtered selection. try it...
 

denton

New Member
Joined
Oct 17, 2006
Messages
20

ADVERTISEMENT

Hello denton, welcome to the board.
For a quick little macro to do what wigi is suggesting:
Code:
Sub Demo()
With Application
  .ScreenUpdating = False
  With Columns("A:A")
    .AutoFilter Field:=1, Criteria1:="<>"
    .Copy Range("C1")
  End With
  ActiveSheet.AutoFilterMode = False
  .CutCopyMode = False
  .ScreenUpdating = True
End With
End Sub

working perfectly! What if i want to do this with 2 columns in sheet1 and results want to have in column C and D (for both columns) in sheet2 ?
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,958
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
but...if i do this, it will copy only first block of non empty cells, not all filtered selection. try it...

Yes, it does. You need to select all the cells before applying the autofilter. Try it...
 

denton

New Member
Joined
Oct 17, 2006
Messages
20
but...if i do this, it will copy only first block of non empty cells, not all filtered selection. try it...

Yes, it does. You need to select all the cells before applying the autofilter. Try it...

perfect! it works! dont know why didnt it work before. Do you think you can help me? I need to make some macro which will copy those numbers to other sheet, but...i have table 40x4 cells (C1:F40). Imagine that filter will find cca 100 numbers- i need to put these numbers to table C1:F40 in sheet2 ->first 40 numbers will be in C1:C40, the 41st will be in D1 and so on,81 st in E1. It is easy to make it handy, but I'd like to make some macro. Would be great if you can help me.
 

Forum statistics

Threads
1,136,927
Messages
5,678,621
Members
419,776
Latest member
mikelowski

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