On Jul 16, 3:24*pm, Brian B <Bri...@discussions.microsoft.com> wrote:
> Hello,
> I'm having trouble with what I would think is a very simple issue. *I would
> like to hide a number of columns but I would like it to be subject to user
> input. *
>
> Here's the very simple code that cuts out the user input:
>
> Columns("C:AH").Select
> Selection.EntireColumn.Hidden = True
>
> But I want column "AH" to be user selectable. *The User would input the
> number '36' (the number of columns over from the left "AH" is) and that'show
> C:AH would be hidden. *
> How do I convert '36' into a Column Range unit? *I've been messing around
> with As Range and haven't been real lucky. *
>
> Thanks in advance for any assistance,
> Brian
Brian,
I'm sure there are MANY ways to do this; I've listed one way below.
(Be sure to qualify your ranges though).
Best,
Matthew Herbert
Dim varInput As Variant
Dim intCnt As Integer
Dim intStartCol As Integer
intStartCol = Range("C1").Column
'You can change the type if you want, i.e. see the VBE Help for
' InputBox Method.
varInput = Application.InputBox("Enter the number of columns to
hide.", _
"Column Hide", Type:=1)
varInput = CInt(varInput)
For intCnt = 1 To varInput
With Cells(1, intStartCol).Offset(0, intCnt)
.EntireColumn.Hidden = True
End With
Next intCnt
|