• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Position a textbox if active cell is within a range

Gandalf

Member
Hello everyone,

I hope you are all well.

I am sure someone will be able to help with this. I have a textbox on and excel sheet that I want to position according to whether the active cell is within one of 3 ranges or do nothing if the active cell is outside of these ranges. The code below does not seem to work

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Me.Range("U1").Value = "=ListPupils!" & ActiveCell.Address

  
    If Intersect(ActiveCell, Range("V6:AN19")) Then
        TxtBoxEnList.Top = 316
        TxtBoxEnList.Left = 1041
    ElseIf Intersect(ActiveCell, Range("V50:AN63")) Then
        TxtBoxEnList.Top = 933
        TxtBoxEnList.Left = 1041
    ElseIf Intersect(ActiveCell, Range("V94:AN107")) Then
        TxtBoxEnList.Top = 1548
        TxtBoxEnList.Left = 1041
End If


End Sub

Thank you for any help

Gandalf
 
Hi Gandalf ,

Change the code slightly as follows :
Code:
PrivateSub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Me.Range("U1").Value = "=ListPupils!" & ActiveCell.Address

    If Not (Intersect(ActiveCell, Range("V6:AN19")) Is Nothing) Then
        TxtBoxEnList.Top = 316
        TxtBoxEnList.Left = 1041
    ElseIf Not (Intersect(ActiveCell, Range("V50:AN63")) Is Nothing) Then
        TxtBoxEnList.Top = 933
        TxtBoxEnList.Left = 1041
    ElseIf Not (Intersect(ActiveCell, Range("V94:AN107")) Is Nothing) Then
        TxtBoxEnList.Top = 1548
        TxtBoxEnList.Left = 1041
EndIf
EndSub
Narayan
 
Hi Narayan,

Superb again, thank you.

I originally had the Is Nothing but not the If Not preceding it

Thanks again

Gandalf
 
Back
Top