PDA

View Full Version : Solved: Help With Hiding Colums



zoom38
06-20-2006, 06:41 PM
I have the following sub to hide the last used column. I found that it does not work on the last worksheet and I can't figure out why. I need to hide the last used column on each worksheet and then I will need to unhide that column after some other procedures. Can you guys take a look and tell me where I went wrong.
Thanks
Gary


Sub HideColumns()
Dim ws As Worksheet
Dim LastColumn As Integer

For Each ws In ThisWorkbook.Worksheets
ws.Activate

'Find The Last Column On The Worksheets
LastColumn = Cells.SpecialCells(xlCellTypeLastCell).Column

'Hide The Last Column
Columns(LastColumn).Hidden = True

Next ws
End Sub

malik641
06-20-2006, 06:50 PM
Don't suppose you could provide a workbook, could you?

I don't see anything wrong with the coding...a look at the book would be more useful.

Ken Puls
06-20-2006, 07:03 PM
I'm curious... does the code seem to hide the wrong column on the last one, or none at all? If it's the wrong column, you may want to delete all columns after the last one and try it again. It may be that you have a space or non printing character buried somewhere that you didn't expect.

HTH,

johnske
06-20-2006, 07:25 PM
Gary,

If you're wanting to hide the last data column, try Cells.Find("*", LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Columnthe xlCellTypeLastCell uses the "UsedRange", and if the last column only has (say) some formatting in it then that is determined as being the last column that was 'used' even though it may contain no data...

HTH,
John

zoom38
06-20-2006, 09:02 PM
Ken you were right, I deleted the remaining columns and it worked thereafter.
John I used your code, seems to work well.
Malik, right now I am unable to post my file because I don't have a zip utility on my work computer and the file is too big.

Thank you gentlemen for the help.
Gary