+ Reply to Thread
Results 1 to 5 of 5

Moved code from worksheet to module

  1. #1
    Phil Floyd
    Guest

    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. #2
    Jim Thomlinson
    Guest

    RE: 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. #3
    Jim Thomlinson
    Guest

    RE: 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. #4
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:%[email protected]...
    > 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. #5
    Phil Floyd
    Guest

    Re: 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" <[email protected]> wrote in message
    news:%[email protected]...
    > 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 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