Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moved code from worksheet to module
I had the following code in a sheet and it worked fine. I moved it to a
module and now I get object required errors. If Target.Address = "$A$3" Then Range("C4") = Range("A3") End If I tried: If Target.Address = Sheets("Sheet").Range("$A$3") Then but that dowsn't work either. How can I do this? Thanks, Phil |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moved code from worksheet to module
When you are writing code within a sheet you need to be explicit in terms of
sheet references... If Target.Address = "$A$3" Then Sheets("Sheet").Range("C4").value = Sheets("Sheet").Range("A3").value End If HTH "Phil Floyd" wrote: I had the following code in a sheet and it worked fine. I moved it to a module and now I get object required errors. If Target.Address = "$A$3" Then Range("C4") = Range("A3") End If I tried: If Target.Address = Sheets("Sheet").Range("$A$3") Then but that dowsn't work either. How can I do this? Thanks, Phil |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moved code from worksheet to module
Sorry Phil I misread the question. If I recall yesterday you had a question
and the reply used the worksheet_selectionchange event. You can not move that code to a module, because the code is triggered by the sheet. If you want to use the exact same code over all sheets, we can help you with that by essentially puttin the code in the ThisWorkbook object in you visual basic. Sorry about my previous reply... HTH "Phil Floyd" wrote: I had the following code in a sheet and it worked fine. I moved it to a module and now I get object required errors. If Target.Address = "$A$3" Then Range("C4") = Range("A3") End If I tried: If Target.Address = Sheets("Sheet").Range("$A$3") Then but that dowsn't work either. How can I do this? Thanks, Phil |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moved code from worksheet to module
It is because Target is unknown. In the sheet code, Target is an argument of
the event, and is set-up when the event triggers. Somehow, in the module, you need to determine what Target is and set it. Maybe just try ACtivecell instead of Target. -- HTH RP (remove nothere from the email address if mailing direct) "Phil Floyd" wrote in message ... I had the following code in a sheet and it worked fine. I moved it to a module and now I get object required errors. If Target.Address = "$A$3" Then Range("C4") = Range("A3") End If I tried: If Target.Address = Sheets("Sheet").Range("$A$3") Then but that dowsn't work either. How can I do this? Thanks, Phil |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moved code from worksheet to module
Thanks for the help guys. Bob's suggestion of changing Target to Activecell
worked perfectly and I am still able to call it from the Worksheet_BeforeDoubleClick event. FYI, this sheet was getting copied into a master workbook and I wanted to reduce the filesize by moving the code in the sheet to a module. Thanks, Phil "Phil Floyd" wrote in message ... I had the following code in a sheet and it worked fine. I moved it to a module and now I get object required errors. If Target.Address = "$A$3" Then Range("C4") = Range("A3") End If I tried: If Target.Address = Sheets("Sheet").Range("$A$3") Then but that dowsn't work either. How can I do this? Thanks, Phil |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VBA Code Help - Moved from an older topic | Excel Discussion (Misc queries) | |||
Where?Worksheet code module or Worksheet_SelectionChange event han | Excel Worksheet Functions | |||
code in module A to not execute a Worksheet_SelectionChange sub of another module | Excel Discussion (Misc queries) | |||
Design Best Practices: Form Control Code in Worksheet or Module | Excel Programming | |||
Problem copying worksheet containing code module | Excel Programming |