Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default Hide Columns if ..................

I have been using a hide rows macro from Frank Kabel
succesfully for a long time.
I now have use for this macro as Hide Columns (instead of rows)
I used Franks macro and tried to replace row references to columns
but end up with Run time error on the most important line.
Can someone help?

Option Explicit
Sub Hide_Columns()
' Hide_Columns Macro
' December 7, 2005
' "transpose" from Frank Kabels Hide Rows Macro
' Keyboard Shortcut: NONE

ActiveSheet.Unprotect Password:="XYZ"

' Dim RowNdx As Long
Dim ColumnNdx As Long

' Dim lastrow As Long
Dim LastColumn As Long

Application.ScreenUpdating = False

' lastrow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row

' THE FOLLOWING comes up with Runtime error 1004
' Application defined or object defined error
' I have no idea what this means, other than something is wrong.

LastColumn = ActiveSheet.Cells(Columns.Count, "1").End(xlLeft).Column


' For RowNdx = lastrow To 1 Step -1
For ColumnNdx = LastColumn To 1 Step -1

' If Cells(RowNdx, "B").Value = "x" Then
' Rows(RowNdx).Hidden = True

If Cells(ColumnNdx, "1").Value = "x" Then
Columns(ColumnNdx).Hidden = True

End If

' Next RowNdx
Next ColumnNdx

Application.ScreenUpdating = True
ActiveSheet.Protect Password:="XYZ"
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Hide Columns if ..................

BEEJAY,

Try this

Sub Hide_Columns()
' Hide_Columns Macro
' December 7, 2005
' "transpose" from Frank Kabels Hide Rows Macro
' Keyboard Shortcut: NONE

ActiveSheet.Unprotect Password:="XYZ"

Dim ColumnNdx As Long

Dim LastColumn As Long

Application.ScreenUpdating = False

LastColumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column

For ColumnNdx = LastColumn To 1 Step -1

If Cells(1, ColumnNdx).Value = "x" Then
Columns(ColumnNdx).Hidden = True

End If

Next ColumnNdx

Application.ScreenUpdating = True
ActiveSheet.Protect Password:="XYZ"
End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)


"BEEJAY" wrote in message
...
I have been using a hide rows macro from Frank Kabel
succesfully for a long time.
I now have use for this macro as Hide Columns (instead of rows)
I used Franks macro and tried to replace row references to columns
but end up with Run time error on the most important line.
Can someone help?

Option Explicit
Sub Hide_Columns()
' Hide_Columns Macro
' December 7, 2005
' "transpose" from Frank Kabels Hide Rows Macro
' Keyboard Shortcut: NONE

ActiveSheet.Unprotect Password:="XYZ"

' Dim RowNdx As Long
Dim ColumnNdx As Long

' Dim lastrow As Long
Dim LastColumn As Long

Application.ScreenUpdating = False

' lastrow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row

' THE FOLLOWING comes up with Runtime error 1004
' Application defined or object defined error
' I have no idea what this means, other than something is wrong.

LastColumn = ActiveSheet.Cells(Columns.Count, "1").End(xlLeft).Column


' For RowNdx = lastrow To 1 Step -1
For ColumnNdx = LastColumn To 1 Step -1

' If Cells(RowNdx, "B").Value = "x" Then
' Rows(RowNdx).Hidden = True

If Cells(ColumnNdx, "1").Value = "x" Then
Columns(ColumnNdx).Hidden = True

End If

' Next RowNdx
Next ColumnNdx

Application.ScreenUpdating = True
ActiveSheet.Protect Password:="XYZ"
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default Hide Columns if ..................

Tried it as suggested. Works Great!!!
Thanks so much.


"Bob Phillips" wrote:

BEEJAY,

Try this

Sub Hide_Columns()
' Hide_Columns Macro
' December 7, 2005
' "transpose" from Frank Kabels Hide Rows Macro
' Keyboard Shortcut: NONE

ActiveSheet.Unprotect Password:="XYZ"

Dim ColumnNdx As Long

Dim LastColumn As Long

Application.ScreenUpdating = False

LastColumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column

For ColumnNdx = LastColumn To 1 Step -1

If Cells(1, ColumnNdx).Value = "x" Then
Columns(ColumnNdx).Hidden = True

End If

Next ColumnNdx

Application.ScreenUpdating = True
ActiveSheet.Protect Password:="XYZ"
End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)


"BEEJAY" wrote in message
...
I have been using a hide rows macro from Frank Kabel
succesfully for a long time.
I now have use for this macro as Hide Columns (instead of rows)
I used Franks macro and tried to replace row references to columns
but end up with Run time error on the most important line.
Can someone help?

Option Explicit
Sub Hide_Columns()
' Hide_Columns Macro
' December 7, 2005
' "transpose" from Frank Kabels Hide Rows Macro
' Keyboard Shortcut: NONE

ActiveSheet.Unprotect Password:="XYZ"

' Dim RowNdx As Long
Dim ColumnNdx As Long

' Dim lastrow As Long
Dim LastColumn As Long

Application.ScreenUpdating = False

' lastrow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row

' THE FOLLOWING comes up with Runtime error 1004
' Application defined or object defined error
' I have no idea what this means, other than something is wrong.

LastColumn = ActiveSheet.Cells(Columns.Count, "1").End(xlLeft).Column


' For RowNdx = lastrow To 1 Step -1
For ColumnNdx = LastColumn To 1 Step -1

' If Cells(RowNdx, "B").Value = "x" Then
' Rows(RowNdx).Hidden = True

If Cells(ColumnNdx, "1").Value = "x" Then
Columns(ColumnNdx).Hidden = True

End If

' Next RowNdx
Next ColumnNdx

Application.ScreenUpdating = True
ActiveSheet.Protect Password:="XYZ"
End Sub




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
Want to Hide columns in spreadsheet but NOT hide data in chart. KrispyData Charts and Charting in Excel 1 March 20th 09 04:45 PM
Hide/Unhide columns using button on top over relevant columns [email protected] Excel Discussion (Misc queries) 1 March 7th 07 09:24 PM
Hide columns cad46230 Excel Discussion (Misc queries) 3 May 13th 06 03:52 PM
Excel button :: Filter columns by value - possible? Additionally, hide certain columns No Name Excel Programming 4 December 28th 04 07:44 PM
Hide Columns rickey24[_4_] Excel Programming 5 June 25th 04 03:08 AM


All times are GMT +1. The time now is 02:57 PM.

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"