Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Code Help - Moved from an older topic jlclyde Excel Discussion (Misc queries) 3 January 10th 08 04:26 PM
Where?Worksheet code module or Worksheet_SelectionChange event han Kenzie Excel Worksheet Functions 4 January 30th 06 09:41 PM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM
Design Best Practices: Form Control Code in Worksheet or Module Bing Excel Programming 2 December 23rd 04 02:31 PM
Problem copying worksheet containing code module Basie[_2_] Excel Programming 1 September 3rd 03 12:28 AM


All times are GMT +1. The time now is 06:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"