Results 1 to 6 of 6

Thread: VBA Code Problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    263
    I have this code in my module that when the Reset Link is clicked it adds a formula to a cell:
    Code:
    Private Sub lblReset_Click()
    Sheets("Employee Feed").Visible = True
    Sheets("Employee Feed").Activate
    Range("A3").Select
    ActiveCell.FormulaR1C1 = "=REPLACE(A7,6,1," - ")"
    End Sub
    It comes up with an error:

    "Type Mismatch"

    What could the problem be??
    Thanks Alot,

    David Gottlieb
    CIW Certified Internet Webmaster
    Web Developer/Designer

  2. #2
    Hyperactive Member
    Join Date
    Nov 2000
    Location
    Mexico City
    Posts
    306

    Wink

    Look at the following expresion:

    "=REPLACE(A7,6,1," - ")"

    What you´re doing is substracting two strings.
    If things were easy, users might be programmers.

  3. #3
    Lively Member
    Join Date
    Jul 2000
    Posts
    70

    Argument type mismatching : string required!

    David,

    REPLACE worksheet function requires arguments with string data type, thus 6 should be "6" and 1 should be "1". Hence, a1 should be reformatted as text or u should convert A1 contents to string by using TEXT(A1,"format-string") ws function.

    Best wishes with your work..

    Kiziltan Yuceil
    Freelance Web/VB/VBA Programmer
    "It's not what you know it's to whom you consult and with whom you collaborate"

  4. #4
    Lively Member
    Join Date
    Jul 2000
    Posts
    70

    Another thing I detected..

    You should use double quotes or chr(34) within formualae string..

    ActiveCell.FormulaR1C1 = "=REPLACE(A7,6,1,"" - "")"
    Kiziltan Yuceil
    Freelance Web/VB/VBA Programmer
    "It's not what you know it's to whom you consult and with whom you collaborate"

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    263
    I'm not sure I understand. I am somewhat new to this. The thing is, I was using this before and it was working fine. I don't understand why it isn't working now
    Thanks Alot,

    David Gottlieb
    CIW Certified Internet Webmaster
    Web Developer/Designer

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    263
    OHHH. Ok. I got it to work. Thank you so much for your help.

    Thank YOU
    Thanks Alot,

    David Gottlieb
    CIW Certified Internet Webmaster
    Web Developer/Designer

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