+ Reply to Thread
Results 1 to 10 of 10

Execute Events Based Upon Selected Cell

  1. #1
    D.Parker
    Guest

    Execute Events Based Upon Selected Cell

    I am trying to program code to execute specific conditions if certain cells
    are selected. I am working within my worksheet and with the
    Worksheet_SelectionChange (ByVal Target As Excel.Range) subroutine. I have
    tried using the AcitveCell.Address per the following example:

    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

    If ActiveCell.Address = Range("H2") Then
    'Range("H2").Value = "X"
    End If

    End Sub

    What has generally happened through my numerous iterations is that the "X"
    is never entered into the selected cell or any other cell for that matter.

    The goal is to have "X" entered into cell H2 only if cell H2 is selected.
    Your assistance is highly appreciated. Any advice or recommendations you may
    have is again well appreciated.

    Kind regards,

    D.Parker





  2. #2
    Jim Thomlinson
    Guest

    RE: Execute Events Based Upon Selected Cell

    Target is the cell you just selected, so here is some code for you...

    Option Explicit

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Select Case Target.Address
    Case "$H$2"
    Target.Value = "X"
    Case "$I$2"
    Target.Value = "X"
    Case "$J$2"
    Target.Value = "X"
    End Select
    End Sub

    HTH

    "D.Parker" wrote:

    > I am trying to program code to execute specific conditions if certain cells
    > are selected. I am working within my worksheet and with the
    > Worksheet_SelectionChange (ByVal Target As Excel.Range) subroutine. I have
    > tried using the AcitveCell.Address per the following example:
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    >
    > If ActiveCell.Address = Range("H2") Then
    > 'Range("H2").Value = "X"
    > End If
    >
    > End Sub
    >
    > What has generally happened through my numerous iterations is that the "X"
    > is never entered into the selected cell or any other cell for that matter.
    >
    > The goal is to have "X" entered into cell H2 only if cell H2 is selected.
    > Your assistance is highly appreciated. Any advice or recommendations you may
    > have is again well appreciated.
    >
    > Kind regards,
    >
    > D.Parker
    >
    >
    >
    >


  3. #3
    Fredrik Wahlgren
    Guest

    Re: Execute Events Based Upon Selected Cell

    Try this. It works for me

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$H$2" Then
    Range("H2").Value = "X"
    End If
    End Sub

    Best Regards
    Fredrik


    "D.Parker" <[email protected]> wrote in message
    news:[email protected]...
    > I am trying to program code to execute specific conditions if certain

    cells
    > are selected. I am working within my worksheet and with the
    > Worksheet_SelectionChange (ByVal Target As Excel.Range) subroutine. I

    have
    > tried using the AcitveCell.Address per the following example:
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    >
    > If ActiveCell.Address = Range("H2") Then
    > 'Range("H2").Value = "X"
    > End If
    >
    > End Sub
    >
    > What has generally happened through my numerous iterations is that the "X"
    > is never entered into the selected cell or any other cell for that matter.
    >
    > The goal is to have "X" entered into cell H2 only if cell H2 is selected.
    > Your assistance is highly appreciated. Any advice or recommendations you

    may
    > have is again well appreciated.
    >
    > Kind regards,
    >
    > D.Parker
    >
    >
    >
    >




  4. #4
    D.Parker
    Guest

    RE: Execute Events Based Upon Selected Cell

    Jim:

    Thank you very much for the response!

    Kind regards,

    Darryl

    "Jim Thomlinson" wrote:

    > Target is the cell you just selected, so here is some code for you...
    >
    > Option Explicit
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > Select Case Target.Address
    > Case "$H$2"
    > Target.Value = "X"
    > Case "$I$2"
    > Target.Value = "X"
    > Case "$J$2"
    > Target.Value = "X"
    > End Select
    > End Sub
    >
    > HTH
    >
    > "D.Parker" wrote:
    >
    > > I am trying to program code to execute specific conditions if certain cells
    > > are selected. I am working within my worksheet and with the
    > > Worksheet_SelectionChange (ByVal Target As Excel.Range) subroutine. I have
    > > tried using the AcitveCell.Address per the following example:
    > >
    > > Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    > >
    > > If ActiveCell.Address = Range("H2") Then
    > > 'Range("H2").Value = "X"
    > > End If
    > >
    > > End Sub
    > >
    > > What has generally happened through my numerous iterations is that the "X"
    > > is never entered into the selected cell or any other cell for that matter.
    > >
    > > The goal is to have "X" entered into cell H2 only if cell H2 is selected.
    > > Your assistance is highly appreciated. Any advice or recommendations you may
    > > have is again well appreciated.
    > >
    > > Kind regards,
    > >
    > > D.Parker
    > >
    > >
    > >
    > >


  5. #5
    D.Parker
    Guest

    Re: Execute Events Based Upon Selected Cell

    Fredrik:

    Also, thank you very much!

    Kind regards,

    Darryl

    "Fredrik Wahlgren" wrote:

    > Try this. It works for me
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > If Target.Address = "$H$2" Then
    > Range("H2").Value = "X"
    > End If
    > End Sub
    >
    > Best Regards
    > Fredrik
    >
    >
    > "D.Parker" <[email protected]> wrote in message
    > news:[email protected]...
    > > I am trying to program code to execute specific conditions if certain

    > cells
    > > are selected. I am working within my worksheet and with the
    > > Worksheet_SelectionChange (ByVal Target As Excel.Range) subroutine. I

    > have
    > > tried using the AcitveCell.Address per the following example:
    > >
    > > Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    > >
    > > If ActiveCell.Address = Range("H2") Then
    > > 'Range("H2").Value = "X"
    > > End If
    > >
    > > End Sub
    > >
    > > What has generally happened through my numerous iterations is that the "X"
    > > is never entered into the selected cell or any other cell for that matter.
    > >
    > > The goal is to have "X" entered into cell H2 only if cell H2 is selected.
    > > Your assistance is highly appreciated. Any advice or recommendations you

    > may
    > > have is again well appreciated.
    > >
    > > Kind regards,
    > >
    > > D.Parker
    > >
    > >
    > >
    > >

    >
    >
    >


  6. #6
    D.Parker
    Guest

    RE: Execute Events Based Upon Selected Cell


    What is the difference between using Excel.Range and just Range in the
    Worksheet_SelectionChange sub? Thank you.

    Kind regards,

    D.Parker

    "Jim Thomlinson" wrote:

    > Target is the cell you just selected, so here is some code for you...
    >
    > Option Explicit
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > Select Case Target.Address
    > Case "$H$2"
    > Target.Value = "X"
    > Case "$I$2"
    > Target.Value = "X"
    > Case "$J$2"
    > Target.Value = "X"
    > End Select
    > End Sub
    >
    > HTH
    >
    > "D.Parker" wrote:
    >
    > > I am trying to program code to execute specific conditions if certain cells
    > > are selected. I am working within my worksheet and with the
    > > Worksheet_SelectionChange (ByVal Target As Excel.Range) subroutine. I have
    > > tried using the AcitveCell.Address per the following example:
    > >
    > > Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    > >
    > > If ActiveCell.Address = Range("H2") Then
    > > 'Range("H2").Value = "X"
    > > End If
    > >
    > > End Sub
    > >
    > > What has generally happened through my numerous iterations is that the "X"
    > > is never entered into the selected cell or any other cell for that matter.
    > >
    > > The goal is to have "X" entered into cell H2 only if cell H2 is selected.
    > > Your assistance is highly appreciated. Any advice or recommendations you may
    > > have is again well appreciated.
    > >
    > > Kind regards,
    > >
    > > D.Parker
    > >
    > >
    > >
    > >


  7. #7
    Chip Pearson
    Guest

    Re: Execute Events Based Upon Selected Cell

    There is no practical difference between declaring a variable As
    Range and As Excel.Range. The only circumstance that would make
    a difference is if an object library is referenced that also has
    an object named Range (e.g., referencing Word from Excel). In
    this case, using the Excel prefix tells the compiler which object
    named Range is intended for use.

    Under normal circumstances, you may safely omit the Excel prefix.


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com


    "D.Parker" <[email protected]> wrote in message
    news:[email protected]...
    >
    > What is the difference between using Excel.Range and just Range
    > in the
    > Worksheet_SelectionChange sub? Thank you.
    >
    > Kind regards,
    >
    > D.Parker
    >
    > "Jim Thomlinson" wrote:
    >
    >> Target is the cell you just selected, so here is some code for
    >> you...
    >>
    >> Option Explicit
    >>
    >> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    >> Select Case Target.Address
    >> Case "$H$2"
    >> Target.Value = "X"
    >> Case "$I$2"
    >> Target.Value = "X"
    >> Case "$J$2"
    >> Target.Value = "X"
    >> End Select
    >> End Sub
    >>
    >> HTH
    >>
    >> "D.Parker" wrote:
    >>
    >> > I am trying to program code to execute specific conditions
    >> > if certain cells
    >> > are selected. I am working within my worksheet and with the
    >> > Worksheet_SelectionChange (ByVal Target As Excel.Range)
    >> > subroutine. I have
    >> > tried using the AcitveCell.Address per the following
    >> > example:
    >> >
    >> > Private Sub Worksheet_SelectionChange(ByVal Target As
    >> > Excel.Range)
    >> >
    >> > If ActiveCell.Address = Range("H2") Then
    >> > 'Range("H2").Value = "X"
    >> > End If
    >> >
    >> > End Sub
    >> >
    >> > What has generally happened through my numerous iterations
    >> > is that the "X"
    >> > is never entered into the selected cell or any other cell
    >> > for that matter.
    >> >
    >> > The goal is to have "X" entered into cell H2 only if cell H2
    >> > is selected.
    >> > Your assistance is highly appreciated. Any advice or
    >> > recommendations you may
    >> > have is again well appreciated.
    >> >
    >> > Kind regards,
    >> >
    >> > D.Parker
    >> >
    >> >
    >> >
    >> >




  8. #8
    D.Parker
    Guest

    Re: Execute Events Based Upon Selected Cell

    Thank you very much!

    D.Parker

    "Chip Pearson" wrote:

    > There is no practical difference between declaring a variable As
    > Range and As Excel.Range. The only circumstance that would make
    > a difference is if an object library is referenced that also has
    > an object named Range (e.g., referencing Word from Excel). In
    > this case, using the Excel prefix tells the compiler which object
    > named Range is intended for use.
    >
    > Under normal circumstances, you may safely omit the Excel prefix.
    >
    >
    > --
    > Cordially,
    > Chip Pearson
    > Microsoft MVP - Excel
    > Pearson Software Consulting, LLC
    > www.cpearson.com
    >
    >
    > "D.Parker" <[email protected]> wrote in message
    > news:[email protected]...
    > >
    > > What is the difference between using Excel.Range and just Range
    > > in the
    > > Worksheet_SelectionChange sub? Thank you.
    > >
    > > Kind regards,
    > >
    > > D.Parker
    > >
    > > "Jim Thomlinson" wrote:
    > >
    > >> Target is the cell you just selected, so here is some code for
    > >> you...
    > >>
    > >> Option Explicit
    > >>
    > >> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > >> Select Case Target.Address
    > >> Case "$H$2"
    > >> Target.Value = "X"
    > >> Case "$I$2"
    > >> Target.Value = "X"
    > >> Case "$J$2"
    > >> Target.Value = "X"
    > >> End Select
    > >> End Sub
    > >>
    > >> HTH
    > >>
    > >> "D.Parker" wrote:
    > >>
    > >> > I am trying to program code to execute specific conditions
    > >> > if certain cells
    > >> > are selected. I am working within my worksheet and with the
    > >> > Worksheet_SelectionChange (ByVal Target As Excel.Range)
    > >> > subroutine. I have
    > >> > tried using the AcitveCell.Address per the following
    > >> > example:
    > >> >
    > >> > Private Sub Worksheet_SelectionChange(ByVal Target As
    > >> > Excel.Range)
    > >> >
    > >> > If ActiveCell.Address = Range("H2") Then
    > >> > 'Range("H2").Value = "X"
    > >> > End If
    > >> >
    > >> > End Sub
    > >> >
    > >> > What has generally happened through my numerous iterations
    > >> > is that the "X"
    > >> > is never entered into the selected cell or any other cell
    > >> > for that matter.
    > >> >
    > >> > The goal is to have "X" entered into cell H2 only if cell H2
    > >> > is selected.
    > >> > Your assistance is highly appreciated. Any advice or
    > >> > recommendations you may
    > >> > have is again well appreciated.
    > >> >
    > >> > Kind regards,
    > >> >
    > >> > D.Parker
    > >> >
    > >> >
    > >> >
    > >> >

    >
    >
    >


  9. #9
    Jim Thomlinson
    Guest

    RE: Execute Events Based Upon Selected Cell

    It is a more explicit declaration. In this case it really will not make any
    difference whatsoever. Usually the more explicit the declaration the better,
    but in this case it doesn't make any difference... If there were to items
    Excel and another that could both have ranges, then you would need to
    explcitle declate what type of range you wanted to use...

    HTH

    "D.Parker" wrote:

    >
    > What is the difference between using Excel.Range and just Range in the
    > Worksheet_SelectionChange sub? Thank you.
    >
    > Kind regards,
    >
    > D.Parker
    >
    > "Jim Thomlinson" wrote:
    >
    > > Target is the cell you just selected, so here is some code for you...
    > >
    > > Option Explicit
    > >
    > > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > > Select Case Target.Address
    > > Case "$H$2"
    > > Target.Value = "X"
    > > Case "$I$2"
    > > Target.Value = "X"
    > > Case "$J$2"
    > > Target.Value = "X"
    > > End Select
    > > End Sub
    > >
    > > HTH
    > >
    > > "D.Parker" wrote:
    > >
    > > > I am trying to program code to execute specific conditions if certain cells
    > > > are selected. I am working within my worksheet and with the
    > > > Worksheet_SelectionChange (ByVal Target As Excel.Range) subroutine. I have
    > > > tried using the AcitveCell.Address per the following example:
    > > >
    > > > Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    > > >
    > > > If ActiveCell.Address = Range("H2") Then
    > > > 'Range("H2").Value = "X"
    > > > End If
    > > >
    > > > End Sub
    > > >
    > > > What has generally happened through my numerous iterations is that the "X"
    > > > is never entered into the selected cell or any other cell for that matter.
    > > >
    > > > The goal is to have "X" entered into cell H2 only if cell H2 is selected.
    > > > Your assistance is highly appreciated. Any advice or recommendations you may
    > > > have is again well appreciated.
    > > >
    > > > Kind regards,
    > > >
    > > > D.Parker
    > > >
    > > >
    > > >
    > > >


  10. #10
    D.Parker
    Guest

    RE: Execute Events Based Upon Selected Cell

    I noticed that the address are locked (i.e. $H$2) as opposed to unlocked
    (i.e. "H2"). Is there a reason for that difference? And how would I change
    the code to unlock the address such that I can support H2, H8, H12, ...?
    Thanks again.

    D. Parker

    "Jim Thomlinson" wrote:

    > It is a more explicit declaration. In this case it really will not make any
    > difference whatsoever. Usually the more explicit the declaration the better,
    > but in this case it doesn't make any difference... If there were to items
    > Excel and another that could both have ranges, then you would need to
    > explcitle declate what type of range you wanted to use...
    >
    > HTH
    >
    > "D.Parker" wrote:
    >
    > >
    > > What is the difference between using Excel.Range and just Range in the
    > > Worksheet_SelectionChange sub? Thank you.
    > >
    > > Kind regards,
    > >
    > > D.Parker
    > >
    > > "Jim Thomlinson" wrote:
    > >
    > > > Target is the cell you just selected, so here is some code for you...
    > > >
    > > > Option Explicit
    > > >
    > > > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > > > Select Case Target.Address
    > > > Case "$H$2"
    > > > Target.Value = "X"
    > > > Case "$I$2"
    > > > Target.Value = "X"
    > > > Case "$J$2"
    > > > Target.Value = "X"
    > > > End Select
    > > > End Sub
    > > >
    > > > HTH
    > > >
    > > > "D.Parker" wrote:
    > > >
    > > > > I am trying to program code to execute specific conditions if certain cells
    > > > > are selected. I am working within my worksheet and with the
    > > > > Worksheet_SelectionChange (ByVal Target As Excel.Range) subroutine. I have
    > > > > tried using the AcitveCell.Address per the following example:
    > > > >
    > > > > Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    > > > >
    > > > > If ActiveCell.Address = Range("H2") Then
    > > > > 'Range("H2").Value = "X"
    > > > > End If
    > > > >
    > > > > End Sub
    > > > >
    > > > > What has generally happened through my numerous iterations is that the "X"
    > > > > is never entered into the selected cell or any other cell for that matter.
    > > > >
    > > > > The goal is to have "X" entered into cell H2 only if cell H2 is selected.
    > > > > Your assistance is highly appreciated. Any advice or recommendations you may
    > > > > have is again well appreciated.
    > > > >
    > > > > Kind regards,
    > > > >
    > > > > D.Parker
    > > > >
    > > > >
    > > > >
    > > > >


+ 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