Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do stuff on change of Excel cell: onchange? 2

Status
Not open for further replies.

VBAguy22

IS-IT--Management
Aug 5, 2003
180
CA
Hi
I need to write some code that will copy some cells and paste them elsewhere as soon as the user puts the cursor on the cell "B3" (or if it can't be done, as soon as the value of "B3" changes) in my Sheet1.
I know there is such a thing as onchange or onclick but I am not sure about syntax?
help please:)
 
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Address = "$B$3" Then
'do your stuff
End If
End Sub


*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
VBAguy22,

You want to put you code in the Worksheet_SelectionChange event.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Set rng = Application.Intersect(Target, Range("B3"))
   If Not rng Is Nothing Then
      SomeOtherRange.Copy Destination:=YetAnotherRange
   End If
End Sub

Skip,

[red]Be advised:[/red] [glasses]
Alcohol and Calculus do not mix!
If you drink, don't derive! [tongue]
 
Yeah, go with SkipVought's, mine will trigger when the selection changes on any sheet.

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
cL,

I occasionally use the Workbook_SheetSelectionChange for processes that need to occur on more than one sheet, In which case, if it were on all sheets starting with tbl...
Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
  If Sh.Name Like "tbl*" Then
    If Target.Address = "$B$3" Then
        'do your stuff
    End If
  End If
End Sub


Skip,

[red]Be advised:[/red] [glasses]
Alcohol and Calculus do not mix!
If you drink, don't derive! [tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top