Results 1 to 10 of 10

Unable to fire Private Sub Worksheet_SelectionChange on user Input

Threaded View

VirEgregius Unable to fire Private Sub... 01-31-2013, 05:40 AM
Norie Re: Unable to fire Private... 01-31-2013, 05:43 AM
VirEgregius Re: Unable to fire Private... 01-31-2013, 05:51 AM
VirEgregius Re: Unable to fire Private... 01-31-2013, 08:10 AM
VirEgregius Re: Unable to fire Private... 01-31-2013, 09:08 AM
Norie You can replace... 01-31-2013, 09:21 AM
VirEgregius Re: Unable to fire Private... 01-31-2013, 09:59 AM
JosephP Re: Unable to fire Private... 01-31-2013, 10:13 AM
VirEgregius Re: Unable to fire Private... 01-31-2013, 10:35 AM
VirEgregius Re: Unable to fire Private... 01-31-2013, 11:02 AM
  1. #1
    Registered User
    Join Date
    01-30-2013
    Location
    Crawley, England
    MS-Off Ver
    Excel 2010
    Posts
    9

    Question Unable to fire Private Sub Worksheet_SelectionChange on user Input

    Good Day All (Please see Most recent post below)

    VBA Skill: Pretty Basic
    Excel type: Excel 2010

    Problem:
    Range("A1:A10") is where my users will enter a text structure; 1.0, 1.1, 1.2, 2.0, 2.1 etc. If the user enters a text string that includes "0" then we would like the code to activate and place a formula Offset(0, 4) from the ActiveCell, the following code is cobbled together from various posts and works to some extent:

    Option Explicit
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Not Application.Intersect(Target, Me.Range("A1:A10")) Is Nothing Then
            ' At least one cell of Target is within the range A1:A10.
            ' Carry out some action.
            If InStr(ActiveCell, "0") Then
                ActiveCell.Offset(0, 4).Formula = "=SUM(1+2)"
            Else
            'Cell does not = 0 So Leave Code
            Exit Sub
        
        End If
        End If
    
    End Sub
    This code activates if we have entered 1.0, 2.0, 3.0 etc however it only works after we return to the Cell (with Keyboard Navigation Keys), what do we need to do to make the code activate on "Enter" or when we leave the ActiveCell; i.e. User inputs 1.0 hits Enter, Tabs or Navigates using the arrow Keys Then Code Activates.

    I wondered if the following would be more effcient than ActiveCell but i can't get it to work with the above code

     If Not Application.Intersect(Target, Me.Range("A1:A10")) Is Nothing Then
            ' At least one cell of Target is within the range A1:A10. 
            ' Carry out some action.
    Any help will be gratefully received

    As advised below; Apologies for delay, my work Internet is rubbish!
    Test Macro Entry via VBA.xlsm
    Last edited by VirEgregius; 01-31-2013 at 08:13 AM. Reason: uploading dumb test Worksheet, forward SuperUser(s) to most recent post

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1