hiding columns

T

texandude

Hi,
I'm trying to hide columns certain columns in my sheet using VB
macro.
Hiding of column should be based on the selection made by the user.

for example I wanna hide Columns X-AW for a view and for other view
wanna hide Column A -X. The logic I'm using is in column X I hav
placed a pointer "eofr"
I look for that using Find method. That works fine but after that th
Range I'm giving to hide Columns fails :( . Please see code below. An
help will be appreciated! :)

Set ExcelLastCell = ActiveSheet.Cells.SpecialCells(xlLastCell)
LastColumn = ExcelLastCell.Column
Column = ExcelLastCell.Column
Do While Application.CountA(ActiveSheet.Columns(Column)) = 0 And Colum
<> 1
Column = Column - 1
Loop
LastColumn = Column

Dim RngCol As Range
Set RngCol = Range("A4:AW4").Find(What:="eofr", After:=Range("D4")
LookAt:=xlWhole, SearchOrder:=xlByColumns)

Columns(RngCol.Column & ":" & LastColumn).Hidden = True
End Su
 
D

Dave Peterson

I'm not quite sure what's going on, but this might work:

Range(Cells(1, rngcol.Column), Cells(1, lastcolumn)).EntireColumn.Hidden = True
 
Top