Macro - hide object when current cell not it target column, any ideas?

Limberg

New Member
Joined
Sep 5, 2015
Messages
2
Hi,

With the help of others' posts I've managed to insert a pop-up date & time picker (Calendar1) that gets activated whenever I select a cell within specific columns (Case Target.Column).

My problem now is that whenever I am working with any other cell not within my Target.Column I would like the Calendar1 not to show any more.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Column
Case 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
    If Calendar1.Visible Then Calendar1.Visible = False
    Calendar1.Left = Target.Left + Target.Width
    Calendar1.Top = Target.Top + Target.Height
    Calendar1.Visible = True
    Calendar1.Value = Date
Case Else
End Select
End Sub

I'm not knowledgeable at all when it comes to VBA language, so I've tried different approaches with no success whatsoever. I assumed that the line If Calendar1.Visible Then Calendar1.Visible = False would do the trick but as far as I can tell, it has no relevance for this macro.

Any piece of advise is greatly appreciated.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Perhaps this:-
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Column
    Case 5 To 16
        Calendar1.Visible = False
    Case 1 To 4
        Calendar1.Visible = True
        Calendar1.Left = Target.Left + Target.Width
        Calendar1.Top = Target.Top + Target.Height
        Calendar1.Value = Date
End Select
End Sub
 
Upvote 0
Perhaps this:-
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Column
    Case 5 To 16
        Calendar1.Visible = False
    Case 1 To 4
        Calendar1.Visible = True
        Calendar1.Left = Target.Left + Target.Width
        Calendar1.Top = Target.Top + Target.Height
        Calendar1.Value = Date
End Select
End Sub

You are fantastic! I was already banging my head against the wall not being able to solve it!
Thanks!
 
Upvote 0

Forum statistics

Threads
1,216,134
Messages
6,129,070
Members
449,485
Latest member
greggy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top