Results 1 to 4 of 4

Thread: [RESOLVED] Linking cells from other sheets formula (EXCEL)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Resolved [RESOLVED] Linking cells from other sheets formula (EXCEL)

    Hi,

    I'm getting a run time error 1004
    Application-defined or object-defined error

    What I'm trying to do is to link the value from another sheet.
    The error is raised at: ActiveCell.Offset...... line

    VB Code:
    1. Sub Linker(Dis As String)
    2. TDis = Dis
    3. With Sheets("Total").Range("A1:A500")
    4.     Set b = .Find(TDis)   'Find the district
    5.     aadd = b.Address
    6. End With
    7. Sheets("Total").Select
    8. ActiveSheet.Range([aadd]).Activate
    9. 'Put the formulas where it should be
    10. ActiveCell.Offset(0, 2).Formula = "= " & TDis & " ! " & gtotactsalesw & " "
    11. End Sub

    The name of the sheet is coming by Dis who is a String
    gtotactsalesw is also a String

    Usually in an excel cell you link a value from another by entering the formula =sheet!cell

    But don't seems to do the trick here.
    Any help or hint would be appreciated.

    thanks

  2. #2
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Linking cells from other sheets formula (EXCEL)

    I didn't verify, but I believe you activate sheets and select ranges, not the other way around. Also, you don't need to select/activate to change the formula. You could use:

    Sheets("Total").Range([aadd]).Offset(0, 2).Formula = "= " & TDis & " ! " & gtotactsalesw & " "

    P.S. why use [aadd] instead of just aadd?

  3. #3
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    Re: Linking cells from other sheets formula (EXCEL)

    What is the value in TDis? If the sheet name contains spaces you need to enclose it in single quotes.
    VB Code:
    1. Sheet1!$A$1
    vs.
    VB Code:
    1. 'Sheet 1'!$A$1
    And out of curiosity, what is the purpose of the trailing space in the derived formula?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Re: Linking cells from other sheets formula (EXCEL)

    VbHack: I use [aadd] because if I just use aadd it does't work at all. Also Sheets("Total").Range([aadd]).Offset(0, 2).Formula = "= " & TDis & " ! " & gtotactsalesw & " " does't seem to work.


    The error seems to be on the right side of the = sign.

    mickeyc1204: you're right again my friend...
    TDis contains : "North S. & Outaouais"

    the space between words is the problem.
    And the trailing space were mistyping...

    Work perfectly

    Thanks again mickey1204

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width