+ Reply to Thread
Results 1 to 6 of 6

how to prevent code running when in a worksheet code

  1. #1
    Corey
    Guest

    how to prevent code running when in a worksheet code

    I have the follow code in the worksheet code to run a popup calendar.
    I have another macro that clears the range of cells,
    but i keep getting the below code running that prevents me clearing the range of cell contents.

    How can i at the start of another macro, stop the below from running, yet still be
    able to have the below to run if the cell is selected in the range NOT by the macro?


    ________________________________________________

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim MyRange As Range
    If Not Intersect(Target, Range("C8:R30")) Is Nothing Then
    Call frmCalendar.Show
    'Call Macro7
    'Call Ids
    'Call Names_Print
    'Call Names_Frequency
    'Call SentenceCase
    'Call Dates
    'Call Shades
    End If
    End Sub

    _______________________________________________

    Corey....

  2. #2
    Carim
    Guest

    Re: how to prevent code running when in a worksheet code

    Hi Corey,

    The easiest solution is to insert a test into your private sub to make
    it exit sub if cell A1 = 1 for example else it will execute your code
    ....

    HTH
    Cheers
    Carim


  3. #3
    Corey
    Guest

    Re: how to prevent code running when in a worksheet code

    Thanks Carim,

    How would i add if the ENTIRE Range of C8:R30 was selected to this code:


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim MyRange As Range
    If Not Intersect(Target, Range("C8:R30")) Is Nothing Then
    Call frmCalendar.Show

    End If
    End Sub


    ??
    Corey....



  4. #4
    Carim
    Guest

    Re: how to prevent code running when in a worksheet code

    Hi Corey,

    I think I did not express myself clearly enough ...
    With a test of your own ...
    say if there is the number 1 in cell A1 then nothing happens,
    otherwise your macro is executed ...

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim MyRange As Range

    If Range("A1").Value = 1 Then
    Exit Sub
    Else
    If Not Intersect(Target, Range("C8:R30")) Is Nothing Then
    Call frmCalendar.Show
    End If
    End If

    End Sub

    Hope this clarifies
    Cheers
    Carim


  5. #5
    Corey
    Guest

    Re: how to prevent code running when in a worksheet code

    thanks again for the reply.
    My problem is that the macro I am trying to run, but needs to stop this
    code,
    simply selects the entire range (c8:r20) and clears the cells.

    As there is no actual value to enter I am a little lost to entering this
    into the code???

    Corey....


    "Carim" <carimfam@yahoo.com> wrote in message
    news:1155455050.971008.179480@b28g2000cwb.googlegroups.com...
    > Hi Corey,
    >
    > I think I did not express myself clearly enough ...
    > With a test of your own ...
    > say if there is the number 1 in cell A1 then nothing happens,
    > otherwise your macro is executed ...
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > Dim MyRange As Range
    >
    > If Range("A1").Value = 1 Then
    > Exit Sub
    > Else
    > If Not Intersect(Target, Range("C8:R30")) Is Nothing Then
    > Call frmCalendar.Show
    > End If
    > End If
    >
    > End Sub
    >
    > Hope this clarifies
    > Cheers
    > Carim
    >




  6. #6
    Corey
    Guest

    Re: how to prevent code running when in a worksheet code

    Sorry for miss understanding.
    I have just worked out what you were saying.
    I added a step so A1=1 to the code
    then at the end
    to CLEAR A1

    to easy after all.

    thanks for the assistance

    Corey....
    "Corey" <coreytroy@exemail.com.au> wrote in message
    news:uBOwL0qvGHA.4756@TK2MSFTNGP02.phx.gbl...
    > thanks again for the reply.
    > My problem is that the macro I am trying to run, but needs to stop this
    > code,
    > simply selects the entire range (c8:r20) and clears the cells.
    >
    > As there is no actual value to enter I am a little lost to entering this
    > into the code???
    >
    > Corey....
    >
    >
    > "Carim" <carimfam@yahoo.com> wrote in message
    > news:1155455050.971008.179480@b28g2000cwb.googlegroups.com...
    >> Hi Corey,
    >>
    >> I think I did not express myself clearly enough ...
    >> With a test of your own ...
    >> say if there is the number 1 in cell A1 then nothing happens,
    >> otherwise your macro is executed ...
    >>
    >> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    >> Dim MyRange As Range
    >>
    >> If Range("A1").Value = 1 Then
    >> Exit Sub
    >> Else
    >> If Not Intersect(Target, Range("C8:R30")) Is Nothing Then
    >> Call frmCalendar.Show
    >> End If
    >> End If
    >>
    >> End Sub
    >>
    >> Hope this clarifies
    >> Cheers
    >> Carim
    >>

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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