Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Date type mismatch

Can someone pls tell me what I'm doing wrong?

Dim startDate As Date
Dim endDate As Date

startDate = Application.Min(Range("a:a"))
endDate = Application.Max(Range("a:a"))

Later, I try to use this in a different sheet I get type mismatch no matter
what I try:

Cells("Cl").Value = "Summary for " & startDate & "- " & endDate

I also found that I need to activate the sheet that has the dates because

With Sheets ("mySheet")
startDate = Application.Min(Range("a:a"))
endDate = Application.Max(Range("a:a"))
End With

is still trying set the dates from the active sheet.

Thanks in advance!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Date type mismatch

Hi Patti,

Cells("Cl").Value


should be

Range("C1") or Cells(1, "C") or Cells(1,3)

Also, to refer to Sheets("mySheet"), inside your With ... End with statement

Application.Min(Range("a:a"))
and
Application.Max(Range("a:a"))

each need a period preceding Range("a:a")

Making these adjustments, this worked for me:

Sub Tester()
Dim startDate As Date
Dim endDate As Date

With Sheets("mySheet")
startDate = Application.Min(.Range("a:a"))
endDate = Application.Max(.Range("a:a"))
End With

ActiveSheet.Range("C1").Value = _
"Summary for " & startDate & "-" & endDate
End Sub


---
Regards,
Norman



"Patti" wrote in message
...
Can someone pls tell me what I'm doing wrong?

Dim startDate As Date
Dim endDate As Date

startDate = Application.Min(Range("a:a"))
endDate = Application.Max(Range("a:a"))

Later, I try to use this in a different sheet I get type mismatch no
matter
what I try:

Cells("Cl").Value = "Summary for " & startDate & "- " & endDate

I also found that I need to activate the sheet that has the dates because

With Sheets ("mySheet")
startDate = Application.Min(Range("a:a"))
endDate = Application.Max(Range("a:a"))
End With

is still trying set the dates from the active sheet.

Thanks in advance!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date type mismatch

With Sheets ("mySheet")
startDate = Application.Min( .Range("a:a"))
endDate = Application.Max( .Range("a:a"))
End With

Put a period in front of Range and you won't have to select the sheet.
Otherwise, using the With construct does nothing.

I don't know why you are getting a type mistmatch. Place

Option Explicit

at the top of all your modules and see if the routine where the error occurs
can see your variables (startDate and endDate)

I don't know where they are declared, but if at the top of a module you
might declare them as

Public startDate As Date
Public endDate As Date

--
Regards,
Tom Ogilvy

"Patti" wrote in message
...
Can someone pls tell me what I'm doing wrong?

Dim startDate As Date
Dim endDate As Date

startDate = Application.Min(Range("a:a"))
endDate = Application.Max(Range("a:a"))

Later, I try to use this in a different sheet I get type mismatch no

matter
what I try:

Cells("Cl").Value = "Summary for " & startDate & "- " & endDate

I also found that I need to activate the sheet that has the dates because

With Sheets ("mySheet")
startDate = Application.Min(Range("a:a"))
endDate = Application.Max(Range("a:a"))
End With

is still trying set the dates from the active sheet.

Thanks in advance!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date type mismatch

Missed that one. Good Catch.

--
Regards,
Tom Ogilvy

"Norman Jones" wrote in message
...
Hi Patti,

Cells("Cl").Value


should be

Range("C1") or Cells(1, "C") or Cells(1,3)

Also, to refer to Sheets("mySheet"), inside your With ... End with

statement

Application.Min(Range("a:a"))
and
Application.Max(Range("a:a"))

each need a period preceding Range("a:a")

Making these adjustments, this worked for me:

Sub Tester()
Dim startDate As Date
Dim endDate As Date

With Sheets("mySheet")
startDate = Application.Min(.Range("a:a"))
endDate = Application.Max(.Range("a:a"))
End With

ActiveSheet.Range("C1").Value = _
"Summary for " & startDate & "-" & endDate
End Sub


---
Regards,
Norman



"Patti" wrote in message
...
Can someone pls tell me what I'm doing wrong?

Dim startDate As Date
Dim endDate As Date

startDate = Application.Min(Range("a:a"))
endDate = Application.Max(Range("a:a"))

Later, I try to use this in a different sheet I get type mismatch no
matter
what I try:

Cells("Cl").Value = "Summary for " & startDate & "- " & endDate

I also found that I need to activate the sheet that has the dates

because

With Sheets ("mySheet")
startDate = Application.Min(Range("a:a"))
endDate = Application.Max(Range("a:a"))
End With

is still trying set the dates from the active sheet.

Thanks in advance!






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Date type mismatch

Thanks Tom & Norman - you guys are the best!

Patti


"Tom Ogilvy" wrote in message
...
With Sheets ("mySheet")
startDate = Application.Min( .Range("a:a"))
endDate = Application.Max( .Range("a:a"))
End With

Put a period in front of Range and you won't have to select the sheet.
Otherwise, using the With construct does nothing.

I don't know why you are getting a type mistmatch. Place

Option Explicit

at the top of all your modules and see if the routine where the error

occurs
can see your variables (startDate and endDate)

I don't know where they are declared, but if at the top of a module you
might declare them as

Public startDate As Date
Public endDate As Date

--
Regards,
Tom Ogilvy

"Patti" wrote in message
...
Can someone pls tell me what I'm doing wrong?

Dim startDate As Date
Dim endDate As Date

startDate = Application.Min(Range("a:a"))
endDate = Application.Max(Range("a:a"))

Later, I try to use this in a different sheet I get type mismatch no

matter
what I try:

Cells("Cl").Value = "Summary for " & startDate & "- " & endDate

I also found that I need to activate the sheet that has the dates

because

With Sheets ("mySheet")
startDate = Application.Min(Range("a:a"))
endDate = Application.Max(Range("a:a"))
End With

is still trying set the dates from the active sheet.

Thanks in advance!






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
type mismatch--how to fix rroach Excel Discussion (Misc queries) 2 July 14th 05 06:23 PM
Type Mismatch Rockee052[_60_] Excel Programming 4 March 7th 04 12:12 AM
Type mismatch Stuart[_5_] Excel Programming 4 February 19th 04 07:54 PM
Type Mismatch Phil Hageman[_3_] Excel Programming 2 January 9th 04 06:11 PM
Type Mismatch on Date Cameron[_4_] Excel Programming 2 December 5th 03 01:56 PM


All times are GMT +1. The time now is 03:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"