Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 64
Default Macros - variable columns

Hello,
Not sure if this question has been answered but I could not find it. I have
a macro that hides a few columns in a spreadsheet. However, everytime I
insert or delete a column in the spreadsheet, the macro only retains the
column number and will no longer hide the columns I want to hide. Is there
an edit I can make to the macro to make it dependent on me inserting or
deleting columns?

Thanks for the help!
-Evan
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macros - variable columns

If you always want to hide certain columns, you could give a cell in that column
a nice name (insert|name in xl2003 menus). Then use that to hide that column.

worksheets("sheetnamehere").range("myStateColumn") .EntireColumn.hidden = true

Or if you can't name the sheet, maybe you know what's in the header (for
example).

Dim FoundCell as range
With worksheets("SheetNameHere").rows(1)
Set FoundCell = .Cells.Find(What:="State", _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
end with

if foundcell is nothing then
'can't find it to hide it!
else
foundcell.entirecolumn.hidden = true
end if




Evan wrote:

Hello,
Not sure if this question has been answered but I could not find it. I have
a macro that hides a few columns in a spreadsheet. However, everytime I
insert or delete a column in the spreadsheet, the macro only retains the
column number and will no longer hide the columns I want to hide. Is there
an edit I can make to the macro to make it dependent on me inserting or
deleting columns?

Thanks for the help!
-Evan


--

Dave Peterson
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
HLOOKUP using variable columns Chuka Excel Worksheet Functions 5 December 4th 08 11:40 PM
Dummy variable in macros BWimer Excel Discussion (Misc queries) 1 April 4th 08 09:21 PM
how to sum columns by variable criteria Jason Excel Discussion (Misc queries) 8 January 7th 08 10:03 PM
Macros with variable data jeannie v Excel Worksheet Functions 2 June 17th 07 10:20 PM
Graphing Variable-length columns Ben M Charts and Charting in Excel 3 May 10th 06 06:23 PM


All times are GMT +1. The time now is 02:57 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"