I assume that PointsToScreenPixelsX comes into play if I want to align the top of my userform with the top of a cell, but what is the statement that does that? Would it be affected by either the position of the Excel window or the worksheet's zoom value?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Thanks, Chip has some remarkable code on his site but I don't see how the link helps me to align the top of my userform with the top of a cell. In my question I simplified it a bit in that I also want to align it at the left edge of the selected cell so that it look like this.
Thanks. It sort of works. In my workbook I have several userforms and in the DisplayUserForm sub I changed date_Form to the name of the userform I wanted to position and I changed Activecell to the range where I wanted it displayed. When I called DisplayUserForm, believe it or not, it displayed the wrong userform but in the right place!
I bet it only works if the workbook only has one userform, or, if there's more than one userform, it shows the one that Excel determines is the first one.
Last edited by MartinLiss; Jul 21st, 2022 at 06:23 PM.
I bet it only works if the workbook only has one userform, or, if there's more than one userform, it shows the one that Excel determines is the first one.
I made an array(1 to 4) of a basic userform, and it cycled through each of them each time I clicked on a certain cell, repositioning the relevant UserForm to be offset(0, 1) from the selected cell, as per the image below.
Code:
Sub PositionForm(ByVal objUserForm As Object, ByVal objPosCell As Range)
I find it's just a matter of calling the PositionForm subroutine with the userform object, and the target cell. I'm not sure why you're experiencing such odd, random userform placements.