Auto-Hide Columns

B

Brian Matlack

Hi!
I want to automatically hide columns on a sheet based on the users
selection of a start date and end date. The user selects a date from a
data validation dropdown list and then a vlookup formula puts the
corrisponding column letter in cells B3 and C3 of the sheet named "Hide
Columns" This is what I have but it keeps giving me an error "Type
Mismatch".

<start code>
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim choice1 As String
Dim choice2 As String
choice1 = Worksheets("Hide Columns").Cells(3, 2)
choice2 = Worksheets("Hide Columns").Cells(3, 3)
On Error GoTo ErrHandler
If choice1 = "" Or choice2 = "" Then
End
Else
Columns("choice1:choice2").Select
Selection.EntireColumn.Hidden = True
Range("A1").Select
End If
ErrHandler:
End Sub
<end code>

Any help would be greatly appreciated. Thanks for your time!!
 
P

paul.robinson

Hi
Change the text:
("choice1:choice2")

to
(choice1 & ":" & choice2)

choice1 and choice2 are already strings, so you need to create the
right text string using them.

regards
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top