Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Help with hiding columns

I have two questions

1) Is there a built-in VBA or Excel function that returns the Column Letter
for any given cell?

2) I would like to know the best way to hide/unhide columns using VBA. I
wrote a For...Next loop using the Sheet.EntireColumn.Hidden = True and it
worked fine until I went to unhide it. It gave me the generic 1004 error.

Any help would be appreciated!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help with hiding columns

Demo'd from the immediate Window:

cells(20,"AA").Activate
? Left(ActiveCell.Address(0,0),1 - (ActiveCell.Column 26))
AA
Cells(3,"B").Select
? Left(ActiveCell.Address(0,0),1 - (ActiveCell.Column 26))
B

Sub BBCC()

For i = 1 To 10
If i Mod 2 = 0 Then
Columns(i).Hidden = True
End If
Next

MsgBox "Take a Look"

For i = 1 To 10
If i Mod 2 = 0 Then
Columns(i).Hidden = False
End If
Next

End Sub

works fine for me.

--
regards,
Tom Ogilvy

"ExcelDave" wrote in message
...
I have two questions

1) Is there a built-in VBA or Excel function that returns the Column

Letter
for any given cell?

2) I would like to know the best way to hide/unhide columns using VBA. I
wrote a For...Next loop using the Sheet.EntireColumn.Hidden = True and it
worked fine until I went to unhide it. It gave me the generic 1004 error.

Any help would be appreciated!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with hiding columns


Hello ExcelDave,

In response to your first question, no there is not a built-in Excel o
VBA function to return the Column letter. You can easily write a macr
to do it. Add a Module to your VBA project and paste this code into it
The macro can be called in VBA or used as a Worksheet function.

VBA Examples:
To return the Column of the Active Cell...
Ltr = ColumnLetter()

To Return the Column of specific Cell...
Ltr = Column(BT256)

Worksheet Examples:
To Return the Column of the Active Cell...
=ColumnLetter()

To Return the Column of a specific Cell...
=Column(BT256)

Macro Code:

Public Function ColumnLetter(Optional Address As Range) As String

Dim Addx

If Address Is Nothing Then
Addx = ActiveCell.Address(True, False)
Else
Addx = Address.Address(True, False)
End If

ColumnLetter = Left(Addx, InStr(1, Addx, "$") - 1)

End Function

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=54572

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Help with hiding columns

Thanks to Tom and Leith for your suggestions! You sure sabved me a lot of
time experimenting.

"Leith Ross" wrote:


Hello ExcelDave,

In response to your first question, no there is not a built-in Excel or
VBA function to return the Column letter. You can easily write a macro
to do it. Add a Module to your VBA project and paste this code into it.
The macro can be called in VBA or used as a Worksheet function.

VBA Examples:
To return the Column of the Active Cell...
Ltr = ColumnLetter()

To Return the Column of specific Cell...
Ltr = Column(BT256)

Worksheet Examples:
To Return the Column of the Active Cell...
=ColumnLetter()

To Return the Column of a specific Cell...
=Column(BT256)

Macro Code:

Public Function ColumnLetter(Optional Address As Range) As String

Dim Addx

If Address Is Nothing Then
Addx = ActiveCell.Address(True, False)
Else
Addx = Address.Address(True, False)
End If

ColumnLetter = Left(Addx, InStr(1, Addx, "$") - 1)

End Function

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=545727


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 Andy the yeti Excel Programming 4 May 11th 07 02:56 PM
hiding columns [email protected] Excel Discussion (Misc queries) 3 July 12th 06 04:42 PM
Hiding columns Richard Excel Programming 1 November 2nd 05 09:24 AM
Hiding columns Adam Excel Discussion (Misc queries) 2 March 31st 05 05:07 PM
Not Hiding Columns SS[_3_] Excel Programming 1 February 11th 04 10:27 PM


All times are GMT +1. The time now is 12:42 AM.

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

About Us

"It's about Microsoft Excel"