+ Reply to Thread
Results 1 to 8 of 8

Type mismatch problem

  1. #1
    Dan
    Guest

    Type mismatch problem

    I have a date in both B1 and B2 (sheet "Macro Data"). In my macro, I have the
    following code:

    Dim EndDate As Date
    Dim StartDate As Date

    StartDate = Sheets("Macro Data").Cells("B1")
    EndDate = Sheets("Macro Data").Cells("B2")

    The above statements are giving me error 13 (type mismatch). What's wrong
    with my statements? How do I reference the date data in my macro? Thanks!

    Dan

  2. #2
    Registered User
    Join Date
    05-14-2006
    Posts
    33
    Instead of:
    StartDate = Sheets("Macro Data").Cells("B1")

    Try:
    StartDate = Sheets("Macro Data").Cells("B1").Value

  3. #3

    Re: Type mismatch problem


    Dan wrote:
    My English is very bad. I hope you can understand what I say .

    The type of "CellS()" is wrong. The Correct is "Cells(row,column)"

    StartDate = Sheets("Macro Data").Cells(2,1)
    EndDate = Sheets("Macro Data").Cells(2,2)

    or you can use

    StartDate = Sheets("Macro Data").Range("B1")
    EndDate = Sheets("Macro Data").Range("B2")

    Aheng
    MSN: [email protected]


  4. #4

    Re: Type mismatch problem


    [email protected] wrote:
    >
    > Sorry, The previous has some wrong,


    The correct is
    StartDate = Sheets("Macro Data").Cells(1,2)
    >
    >

    Aheng
    > MSN: [email protected]



  5. #5

    Re: Type mismatch problem

    You can also do sheets("Macro Data").range("A2")
    [email protected] wrote:
    > [email protected] wrote:
    > >
    > > Sorry, The previous has some wrong,

    >
    > The correct is
    > StartDate = Sheets("Macro Data").Cells(1,2)
    > >
    > >

    > Aheng
    > > MSN: [email protected]



  6. #6
    Dan
    Guest

    Re: Type mismatch problem

    When I use

    StartDate = Sheets("Macro Data").Range("B1").Value

    it works. If I use

    StartDate = Sheets("Macro Data").Cells("B1").Value

    I get the type mismatch error. This is my first attempt to use macros in
    Excel. What is the difference between Range and Cells?

    Dan


    "[email protected]" wrote:

    > You can also do sheets("Macro Data").range("A2")
    > [email protected] wrote:
    > > [email protected] wrote:
    > > >
    > > > Sorry, The previous has some wrong,

    > >
    > > The correct is
    > > StartDate = Sheets("Macro Data").Cells(1,2)
    > > >
    > > >

    > > Aheng
    > > > MSN: [email protected]

    >
    >


  7. #7

    Re: Type mismatch problem

    Cells requires the row/col co-ordinates - see the examples above, range
    will allow a text string
    Dan wrote:
    > When I use
    >
    > StartDate = Sheets("Macro Data").Range("B1").Value
    >
    > it works. If I use
    >
    > StartDate = Sheets("Macro Data").Cells("B1").Value
    >
    > I get the type mismatch error. This is my first attempt to use macros in
    > Excel. What is the difference between Range and Cells?
    >
    > Dan
    >
    >
    > "[email protected]" wrote:
    >
    > > You can also do sheets("Macro Data").range("A2")
    > > [email protected] wrote:
    > > > [email protected] wrote:
    > > > >
    > > > > Sorry, The previous has some wrong,
    > > >
    > > > The correct is
    > > > StartDate = Sheets("Macro Data").Cells(1,2)
    > > > >
    > > > >
    > > > Aheng
    > > > > MSN: [email protected]

    > >
    > >



  8. #8
    Dan
    Guest

    Re: Type mismatch problem

    Okay. That's helpful. Thanks!

    Dan

    "[email protected]" wrote:

    > Cells requires the row/col co-ordinates - see the examples above, range
    > will allow a text string
    > Dan wrote:
    > > When I use
    > >
    > > StartDate = Sheets("Macro Data").Range("B1").Value
    > >
    > > it works. If I use
    > >
    > > StartDate = Sheets("Macro Data").Cells("B1").Value
    > >
    > > I get the type mismatch error. This is my first attempt to use macros in
    > > Excel. What is the difference between Range and Cells?
    > >
    > > Dan
    > >
    > >
    > > "[email protected]" wrote:
    > >
    > > > You can also do sheets("Macro Data").range("A2")
    > > > [email protected] wrote:
    > > > > [email protected] wrote:
    > > > > >
    > > > > > Sorry, The previous has some wrong,
    > > > >
    > > > > The correct is
    > > > > StartDate = Sheets("Macro Data").Cells(1,2)
    > > > > >
    > > > > >
    > > > > Aheng
    > > > > > MSN: [email protected]
    > > >
    > > >

    >
    >


+ 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