Thread: Hiding Columns
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Hiding Columns

The following code should work very quickly.

Public Sub MyHide()

'Unhide all columns on worksheet
Cells.EntireColumn.Hidden = False

'Find '1' in row 3
On Error GoTo notFound 'Trap if not found
Rows("3:3").Find(What:="1", _
After:=Cells(3, 1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Activate

On Error GoTo 0 'Turn off error trapping

'Hide all columns from found cell to right of worksheet
Range(ActiveCell, Cells(ActiveCell.Row, Columns.Count)) _
.EntireColumn.Hidden = True

GoTo skipNotfound

notFound:
MsgBox "No value of 1 was found in row 3"

skipNotfound:
Range("A3").Select
End Sub

Regards,

OssieMac