Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default vba code to filter

I have a complex spreadsheet which has blanks so therefore i can't us
advanced filter. There are too many columns to create a macro to us
autofilter so I was wondering if there is any vba code which will allo
me to filter all columns other than the current year. The data goes bac
to 1996.

Cheer

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default vba code to filter

Hi

This will hide rows where col A date has another year than entered. Select
Cancel in the dialog to unhide all.

Sub test()
Dim L As Long, Yr As Long
L = 1
Yr = Val(InputBox("year to show:"))
If Yr = 0 Then
Application.ScreenUpdating = False
Do
L = L + 1
Rows(L).Hidden = False
Loop Until Cells(L, 1).Value = ""
Application.ScreenUpdating = True
Else
Application.ScreenUpdating = False
Do
L = L + 1
If Year(Cells(L, 1).Value) = Yr Then
Rows(L).Hidden = False
Else
Rows(L).Hidden = True
End If
Loop Until Cells(L, 1).Value = ""
Application.ScreenUpdating = True
End If
End Sub


HTH. Best wishes Harald

"rbekka33 " skrev i melding
...
I have a complex spreadsheet which has blanks so therefore i can't use
advanced filter. There are too many columns to create a macro to use
autofilter so I was wondering if there is any vba code which will allow
me to filter all columns other than the current year. The data goes back
to 1996.

Cheers


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default vba code to filter

hi,

when i run this it stops at
If Year(Cells(L, 1).Value) = Yr Then

I type in the dialogue box

2004 Total

any ideas

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default vba code to filter

"rbekka33 " skrev i melding
...

I type in the dialogue box
2004 Total
any ideas?


I said "where col A date has another year than entered". If the dates are
not in column A, or if your data is not dates but something else, then you
must either modify the code or tell us what and where your data is. "2004
total" is not a year (but my code should be able to extract 2004 from that
entry, so the problem is elsewhere).

Best wishes Harald


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default vba code to filter

The spreadsheet has 52 columns contain (in date format "2004 Jul" as
custom number except for the Total columnns eg"2004 Total") dat
starting at column P. In the previous columns there is product info
including country regions etc. I only need to test for data that is fo
the current year for this particular macro and the number of column
increments every month-from 1 -12.

Why i need to do this is that once I have filtered the data, I the
need to match it against the source spreadsheet to determine brand ne
product codes as these rows will need to be imported differently fro
the ones that already exist. once imported the new codes then nee
custom formatting.

With the old codes i only bring across relevant columns. with the ne
codes i need to bring across everything.

I could I guess do this from a pivot table and hide the blanks and the
match the source product code column against the pivot table. I wa
hoping to be able not to have to create a pivot table as it run
slowly.

Any ideas or is more info needed?
Thanks for your patience

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default vba code to filter

My initial code just hid/unhid rows, I figured this might be for printing or
something. I don't really understand the data layout (like why multiple
total cells on each row ?), and hate to say I'm out of ideas on this.

Best wishes Harald

"rbekka33 " skrev i melding
...
The spreadsheet has 52 columns contain (in date format "2004 Jul" as a
custom number except for the Total columnns eg"2004 Total") data
starting at column P. In the previous columns there is product info,
including country regions etc. I only need to test for data that is for
the current year for this particular macro and the number of columns
increments every month-from 1 -12.

Why i need to do this is that once I have filtered the data, I then
need to match it against the source spreadsheet to determine brand new
product codes as these rows will need to be imported differently from
the ones that already exist. once imported the new codes then need
custom formatting.

With the old codes i only bring across relevant columns. with the new
codes i need to bring across everything.

I could I guess do this from a pivot table and hide the blanks and then
match the source product code column against the pivot table. I was
hoping to be able not to have to create a pivot table as it runs
slowly.

Any ideas or is more info needed?
Thanks for your patience.


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter Date Code for macro mulehead Excel Discussion (Misc queries) 2 September 22nd 07 01:13 AM
Filter isn't working with a VBA Code [email protected] Excel Worksheet Functions 8 June 15th 06 01:20 PM
filter code help scrabtree[_2_] Excel Programming 2 August 1st 04 10:09 PM
Filter Code Ray Kanner[_2_] Excel Programming 4 April 29th 04 02:53 PM
vba filter code Gabriel[_3_] Excel Programming 3 February 22nd 04 06:24 PM


All times are GMT +1. The time now is 11:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"