Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

How do I properly align UserForm next to active cell?

$
0
0

I have a UserForm of a MonthView that successfully opens when I click in the specified range of cells, and this SO thread gave me the basic script. It functions, but it doesn't seem to put the UserForm where I'd expect.

Here is the current script (that I have placed in a specific worksheet) to open the UserForm when I click any cell in range B3:C2000:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Set oRange = Range("B3:C2000")
    If Not Intersect(Target, oRange) Is Nothing Then
        frmCalendar.Show
        frmCalendar.Top = ActiveCell.Offset(0, 0).Top
        frmCalendar.Left = ActiveCell.Offset(0, 1).Left
    End If
End Sub

Question 1: I have the UserForm StartUpPosition property set to 0 - Manual - is this correct?

Question 2: When I click any cell in the specified range, for the first time after opening the workbook, the UserForm always opens in the far top left corner of the screen. Why?

Question 3: When I click any cell in the specified range, for any clicks after the first, the UserForm opens relative to the previous cell that was active, instead of the one I just clicked. How do I get it to open relative to the cell just clicked, instead of relative to the previous active cell?

Question 4: Why does it appear to align the bottom of the UserForm instead of the top?

After I do the following steps:
1 - Click cell C15
2 - UserForm opens
3 - Close UserForm
4 - Click cell 16
5 - UserForm opens

This is what I see:

Original result

EDIT: Here is the result after implementing J. Garth's solution (and changing the Offset property to (0, 2):

Correct result


Viewing all articles
Browse latest Browse all 88854


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>