Type mismatch problem

G

Guest

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
 
C

C01d

Instead of:
StartDate = Sheets("Macro Data").Cells("B1")

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

sam.kwan

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: (e-mail address removed)
 
G

Guest

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
 
A

aidan.heritage

Cells requires the row/col co-ordinates - see the examples above, range
will allow a text string
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top