Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Hiding columns by Macro

Thanks to Chip Pearson for supplying the following formula
But can somebody explain it to me !!
There are a couple of functions that are new to me.
Just as a refresher, I am trying to hide the 2nd last
column of a spreadsheet, and that column is a different
column number each month.....but always the 2nd last.

Range(Range("A1"), Cells(1, Columns.Count).End(xlToLeft)
(1, 0)) _ .EntireColumn.Hidden = True

Regards
Michael

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Hiding columns by Macro

Michael,

The formula works as follows:

Range(Rng1, Rng2).EntireColumn.Hidden = True
where
Rng1 = Range("A1")
Rng2 = Cells(1,Columns.Count).End(xlToLeft)(1,0)

The first should be self-explanatory. Lets break down the
second. It starts with

Cells(1,Columns.Count)
or
Cell(1,256)
which is the same as Range("IV1")

Then, from this range, it uses End(xlToLeft) to skip empty
columns moving to the to left, arriving at the last non-blank
entry in row 1. Finally, it uses (1,0) to move one additional
column to the left, which is the second-to-last non-blank entry
in the row.

Combining the two ranges, we get a range starting at A1 and
ending at the second to last non-blank column in row 1. We
finally use EntireColumn to get a reference to the entire columns
in that range, and set the Hidden property to True.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Michael Mitchelson" wrote
in message ...
Thanks to Chip Pearson for supplying the following formula
But can somebody explain it to me !!
There are a couple of functions that are new to me.
Just as a refresher, I am trying to hide the 2nd last
column of a spreadsheet, and that column is a different
column number each month.....but always the 2nd last.

Range(Range("A1"), Cells(1, Columns.Count).End(xlToLeft)
(1, 0)) _ .EntireColumn.Hidden = True

Regards
Michael



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
Hiding Columns Gord Dibben Excel Discussion (Misc queries) 0 February 25th 09 08:49 PM
macro and deleting or hiding columns Pascale Excel Discussion (Misc queries) 4 March 8th 07 02:36 PM
Hiding columns without usimg a macro Mick Excel Worksheet Functions 3 January 30th 07 09:53 PM
Hiding Columns Ruan[_3_] Excel Programming 0 November 13th 03 11:42 PM
Hiding columns in VB Rick B[_4_] Excel Programming 6 November 12th 03 07:22 PM


All times are GMT +1. The time now is 04:00 AM.

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"