How to choose a specific cell when a form closes

Diving_Dan

Board Regular
Joined
Oct 20, 2019
Messages
161
Hi all,

I'm quite new here and new to vba. I have a worksheet that opens a pop up calendar when I click on a certain cell. When I then click on a date on that pop up it puts the date into that particular cell and then the calendar closes. This is all good and working.

Is there a way that when the calendar closes a certain cell is activated/chosen. My calendar is linked to cell H2. When I click on a date on the pop up H2 is populated with that date and the calendar closes. What I would like is for A2 to be chosen rather than H2 remaining the chosen cell.

Is this possible?

Thanks in advance.

This is the current coding I have for the form
Code:
Private Sub cmdClose_Click()    Unload Me
End Sub


Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
    On Error Resume Next
    ActiveCell.Value = DateClicked
    Unload Me
End Sub


Private Sub UserForm_Initialize()
    If IsDate(ActiveCell.Value) Then
        Me.MonthView1.Value = ActiveCell.Value
    End If
End Sub
This is the code I have within the module for my calendar to pop up.
Code:
Sub OpenCalendar()    frmCalendar.Show
End Sub
And this is the code I have within the sheet
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If (Target.Count = 1) Then
    If Not Intersect(Target, Range("H2")) Is Nothing Then frmCalendar.Show
    End If
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
How about
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If (Target.Count = 1) Then
        If Not Intersect(Target, Range("H2")) Is Nothing Then
            frmCalendar.Show
            Range("A2").Select
        End If
    End If
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
I now seem to be getting this error if i try to select all cells

Run-time error '6':
Overflow

If i click on debug there seems to be an error with the second line of code

Any suggestions?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   [COLOR=#ff0000] If (Target.Count = 1) Then[/COLOR]
        If Not Intersect(Target, Range("H2")) Is Nothing Then
            frmCalendar.Show
            Range("A2").Select
        End If
    End If
End Sub
 
Upvote 0
Strange, i closed it and went back into it and I now don't have the option to debug, but I still get the error message???
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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