每个ActiveCell Clicked的Position Userform的位置不同 [英] Position Userform differently for each ActiveCell Clicked
问题描述
我有一个MonthView和DTPicker的用户窗体,当单击某些单元格时将填充它。我的表单定位在第一个单元格的正下方,但是希望将其填充到每个活动单元格的正下方。我当前激活的代码定位用户表单是:
I have a UserForm of a MonthView and DTPicker that will populate when certain cells are clicked. I have the form positioned for directly below the first cell, but would like it to populate right under each active cell that I tell it to activate on. My current activate code to position the user form is:
Private Sub UserForm_Activate()
With frmCalendar
.Top = Application.Top + 340
.Left = Application.Left + 330
End With
End Sub
和我的工作表选择更改代码,将在某些单元格点击时启动用户窗体:
and my worksheet selection change code, which will launch the userform upon certain cell clicks is:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Range("H10,H15")) Is Nothing Then
frmCalendar.Show
End If
End Sub
我知道有一些加载项帮助做到这一点,但是'想知道如何将用户表单定位在上面提到的单元格(H10,H14,H15)之下,而不使用加载项。我需要添加代码到工作表子或激活子?这是什么代码?
I know there are add-ins out there that help do this, but I'd like to figure out how to position the user form right below the cells mentioned above (H10, H14, H15) without using an add-in. Do I need to add code to the worksheet sub or the activate sub?? What code would that be?
谢谢。
编辑:
我刚刚将Activate子代码更改为
I have just changed the Activate Sub code to
Private Sub UserForm_Activate()
With frmCalendar
.Top = ActiveCell.offset(31).Top
.Left = ActiveCell.offset(1).Left
End With
End Sub
这个单元格的右侧略微移动,但是当我尝试在另一个细胞上实际上是进一步向下移动,但是保持与右边相同的距离。这仍然是凌乱的。没有办法使用这些方法将此表单直接置于ActiveCell下方。
This moves it slightly below and slightly to the right of the cell, but when I try it on another cell is actually moves further down but stays the same distance to the right. This it still is messy. There is no way to position this form directly below the ActiveCell using these methods?
推荐答案
您正在使用正确的事件宏。我在工作表中放置了一个TextBox,并且使用这个宏
You are using the correct Event macro. I placed a TextBox in the worksheet and with this macro
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim s As Shape
Set s = ActiveSheet.Shapes(1)
s.Top = ActiveCell.Offset(1, 1).Top
s.Left = ActiveCell.Offset(1, 1).Left
End Sub
我可以让TextBox移动到右边,就在下面活动单元。
I can get the TextBox to move just to the right and just below the activecell.
这篇关于每个ActiveCell Clicked的Position Userform的位置不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!