Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Hide the current month columns

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hamad.fatima@gmail.com - 28 Feb 2006 21:37 GMT
I am creating a monthly forecast sheet. There are columns P to Z listed
as forecast columns with the MOnths  ( Jan to Dec).
Cell A1 in the sheet is the currrent month cell which changes every
month.

I want the sheet ot hide the current month column. Suppose if A1= Jan,
then  column "P( Jan ) " should hide itself. Similarly if the current
month A1= June then the columns "P to U" should hide.

I would greatly appreciate if someone cold help me with this problem.

Thanks
Bob Phillips - 28 Feb 2006 22:16 GMT
   iCol = Application.Match(A1,Range("P1:Z1"),0)
   Columns("P:P").Resize(iCol-15).Hidden = True

This assumes that A1 has the month name string, not a date,a s does P1:Z1,
and that all months are in that range.
--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

> I am creating a monthly forecast sheet. There are columns P to Z listed
> as forecast columns with the MOnths  ( Jan to Dec).
[quoted text clipped - 8 lines]
>
> Thanks
hamad.fatima@gmail.com - 28 Feb 2006 22:42 GMT
Thanks Bob,
I tried to use this but its giving me error. and not working. Is there
any other way to do achieve the results.

Thanks
Bob Phillips - 28 Feb 2006 22:53 GMT
Sorry, here is a correction

   iCol = Application.Match(Range("A1"), Range("P1:Z1"), 0)
   Columns("P:P").Resize(iCol).Hidden = True

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

> Thanks Bob,
> I tried to use this but its giving me error. and not working. Is there
> any other way to do achieve the results.
>
> Thanks
hamad.fatima@gmail.com - 28 Feb 2006 23:04 GMT
Bob It gives me the following error

Run Time error 1004
Application defined or object defined error.

I m not good in macros.If there is something missing that i m not
adding then please let me know.

thanks again
Simon Lloyd - 28 Feb 2006 22:21 GMT
Hi you can try this, the first lot of code gets pasted into the cod
sheet for sheet1 (assuming this is where you want to do the business
and the next lot can just go in a module of its own, it worked for me
When you activate the sheet it will hide the column that has the heade
matching A1 when you close the work book it will un hide all column
ready for the next time you open it, i'm sure there are better ways o
achieving this but this should get you started.

Simon

Private Sub Worksheet_Activate()
Dim Rng As Range
Dim mycell
With Sheets("Sheet1")
Set Rng = Range("P1:Z1")
For Each mycell In Rng
If mycell.Text = Range("A1").Text Then
mycell.EntireColumn.Select
Selection.EntireColumn.Hidden = True
End If
Next mycell
End With
End Sub

Sub Auto_Close()
Cells.Select
Selection.EntireColumn.Hidden = False
End Su
hamad.fatima@gmail.com - 28 Feb 2006 22:40 GMT
Thanks Simon,
I tried to use the Macro , but it hides all the columns from C to Z. I
could not understand why? Can you guide me more in this problem.

Thanks
Tom Ogilvy - 28 Feb 2006 23:02 GMT
It only works from P to Z.  It will have no effect on columns before P
unless you have Merged cells.  Do you have merged cells in your sheet?

Signature

Regards,
Tom Ogilvy

> Thanks Simon,
> I tried to use the Macro , but it hides all the columns from C to Z. I
> could not understand why? Can you guide me more in this problem.
>
> Thanks
hamad.fatima@gmail.com - 28 Feb 2006 23:07 GMT
Thanks ....Yes I had a first rwo as merged cells. Its working now.
Thanks sooooo much.
hamad.fatima@gmail.com - 28 Feb 2006 22:41 GMT
Thanks Simon,
I tried to use the Macro , but it hides all the columns from C to Z. I
could not understand why? Can you guide me more in this problem.

Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.