Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Combo column identifier

I'm working on a set of worksheets in a workbook where I want to use a
macro to Hide certain columns before I protect them send them out to
end users. The starting column that I want to hide varies, depending on
how many columns of data there are in that particular sheet. On every
sheet, however, the columns I want to hide start with one that has the
text "Top 10" in the third row. The hidden columns end at Column AC in
all sheets.
My current thinking is to write a macro that selects row 3 and finds
the work "Top". Set the column as a variable "TopCol", then have XL
hide all columns from that column to Column AC. But I can't figure out
how to tell XL I want to select all columns from a variable, TopCol, to
a constant "AC". I know how to do ("AA:AC"), but what is the syntax
when one of the column identifiers is a variable, the other the normal
alpha label?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Combo column identifier

Dave,

This assumes you have the code to find your variable column:

Sub test()

Dim top_col As Range
Dim cols_to_hide As Range

Set top_col = Columns("AA") 'code to determine top_col will replace this

Set cols_to_hide = Range(top_col, Columns("AC"))
cols_to_hide.Hidden = True

End Sub

hth,

Doug

"davegb" wrote in message
oups.com...
I'm working on a set of worksheets in a workbook where I want to use a
macro to Hide certain columns before I protect them send them out to
end users. The starting column that I want to hide varies, depending on
how many columns of data there are in that particular sheet. On every
sheet, however, the columns I want to hide start with one that has the
text "Top 10" in the third row. The hidden columns end at Column AC in
all sheets.
My current thinking is to write a macro that selects row 3 and finds
the work "Top". Set the column as a variable "TopCol", then have XL
hide all columns from that column to Column AC. But I can't figure out
how to tell XL I want to select all columns from a variable, TopCol, to
a constant "AC". I know how to do ("AA:AC"), but what is the syntax
when one of the column identifiers is a variable, the other the normal
alpha label?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Combo column identifier

I tried running your code with mine, but there's a problem with my code
being based on finding a cell, not a range, and your code looking for a
range input. At this point, it looks like:

Sub Macro1()

Dim TopCol As Range
Dim Cols2Hide As Range

Rows("3:3").Select
Selection.Find(What:="top", After:=ActiveCell, LookIn:=xlFormulas,
_
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False).Activate
Set TopCol = ActiveCell.Column
Set Cols2Hide = Range(TopCol, Columns("AC"))
Cols2Hide.Hidden = True

End Sub

I'm getting a type mismatch at "Set TopCol=ActiveCell.column". I
understand why, just don't know how to fix it. Never do!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Combo column identifier

Dave,

This works for me:

Sub test()

Dim top_cell As Range
Dim TopCol As Range
Dim Cols2Hide As Range

Set top_cell = Rows(3).Find(What:="top", LookIn:=xlValues)
Set TopCol = Columns(top_cell.Column)
Set Cols2Hide = Range(TopCol, Columns("AC"))
Cols2Hide.Hidden = True

End Sub

Doug

"davegb" wrote in message
oups.com...
I tried running your code with mine, but there's a problem with my code
being based on finding a cell, not a range, and your code looking for a
range input. At this point, it looks like:

Sub Macro1()

Dim TopCol As Range
Dim Cols2Hide As Range

Rows("3:3").Select
Selection.Find(What:="top", After:=ActiveCell, LookIn:=xlFormulas,
_
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False).Activate
Set TopCol = ActiveCell.Column
Set Cols2Hide = Range(TopCol, Columns("AC"))
Cols2Hide.Hidden = True

End Sub

I'm getting a type mismatch at "Set TopCol=ActiveCell.column". I
understand why, just don't know how to fix it. Never do!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Combo column identifier

Worked great, Doug. Thanks!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Combo column identifier

I've been modifying the code Doug gave me to hide the columns in every
worksheet in the workbook. But I'm getting an error, "Object variable
or with block variable not set" when I run the following:

Sub AllSheetsColHide()
'for all sheets in currently active workbook, assigned to button

Dim TopCell As Range
Dim TopCol As Range
Dim Cols2Hide As Range
Dim wkSht As Object

For Each wkSht In ActiveWorkbook.Worksheets

Set TopCell = Rows(3).Find(What:="top", LookIn:=xlValues)
Set TopCol = Columns(TopCell.Column)
<------------------------[error here]
Set Cols2Hide = Range(TopCol, Columns("AC"))
Cols2Hide.Hidden = True

Next wkSht

End Sub

Any suggestions? Thanks in advance!

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
Row and Column identifier tabs now showing on sheet 1 George Setting up and Configuration of Excel 2 April 18th 10 04:11 AM
Combo Stacked column/column/line TGags Charts and Charting in Excel 1 September 2nd 09 03:01 AM
Adding a unique identifier to a column of data Holly[_2_] Excel Worksheet Functions 2 December 9th 07 07:01 PM
Unique identifier Steve Barnett Excel Discussion (Misc queries) 19 January 6th 06 11:26 AM
Stacked column and column combo chart KG Charts and Charting in Excel 5 March 16th 05 02:01 PM


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