Set Focus

  • Thread starter Thread starter JLong
  • Start date Start date
J

JLong

I am using the Worksheet_SelectionChanged event to show a
ComboBox on the selected cell so the user could select an
item from the list, note that using datan validation
didn't work because the worksheet zoom factor is 60%.
Everything works fine except that when the combobox is
shown the user could select either the box or cell,
depending on how he clicks on the box. Is there a way of
setting the focus onto the box? Also, is it possible to
call a function on the sheet object from the thisworkbook,
and how?
 
This worked for me when I selected A1:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("a1")) Is Nothing Then Exit Sub
Me.ComboBox1.Activate
End Sub

I put this test function in the same worksheet module (behind sheet1):

Function myFunc(myVal As Double) As Double
myFunc = myVal * 2
End Function

And if you're calling the function in the worksheet module from a sub in the
same module, you can just call it directly:

msgbox myFunc(8)

If you're calling it from some other module:

Option Explicit
Sub testme()
Dim myVal As Double
myVal = Sheet1.myFunc(5)
MsgBox myVal
End Sub

Use the codename for the sheet that owns the code.
 
Back
Top