Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default WorksheetFunction.Match


Hi. Can someone please pinpoint the error in this match function statement
using a textbox which contains the lookup date to match a column of dates in
column Z. Program works if I do not use the textbox otherwise it gives a
runtime error:

Set StartDate = Worksheets("Data1").Range("Z" &
WorksheetFunction.Match(DateValue(TextBox1.Value),
Worksheets("Data1").Range("Z3:Z600"), 0) + 2)

StartDate declared as a range object.
Dates are in 3/14/01 format.
Textbox1 contains a date
Column Z is a series of dates

When I replace the textbox with a cell to contain the lookup date, the rest
of the program works. So the error can be narrowed to this sub expression:
DateValue(TextBox1.Value)

Thanks for your advice.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default WorksheetFunction.Match


Try

Set StartDate = Worksheets("Data1").Range("Z" &
WorksheetFunction.Match(DateValue(TextBox1),
Worksheets("Data1").Range("Z3:Z600").Value, 0) + 2)

If this post helps click Yes
---------------
Jacob Skaria


"John P" wrote:

Hi. Can someone please pinpoint the error in this match function statement
using a textbox which contains the lookup date to match a column of dates in
column Z. Program works if I do not use the textbox otherwise it gives a
runtime error:

Set StartDate = Worksheets("Data1").Range("Z" &
WorksheetFunction.Match(DateValue(TextBox1.Value),
Worksheets("Data1").Range("Z3:Z600"), 0) + 2)

StartDate declared as a range object.
Dates are in 3/14/01 format.
Textbox1 contains a date
Column Z is a series of dates

When I replace the textbox with a cell to contain the lookup date, the rest
of the program works. So the error can be narrowed to this sub expression:
DateValue(TextBox1.Value)

Thanks for your advice.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default WorksheetFunction.Match


Still won't work, Jacob

"Jacob Skaria" wrote:

Try

Set StartDate = Worksheets("Data1").Range("Z" &
WorksheetFunction.Match(DateValue(TextBox1),
Worksheets("Data1").Range("Z3:Z600").Value, 0) + 2)

If this post helps click Yes
---------------
Jacob Skaria


"John P" wrote:

Hi. Can someone please pinpoint the error in this match function statement
using a textbox which contains the lookup date to match a column of dates in
column Z. Program works if I do not use the textbox otherwise it gives a
runtime error:

Set StartDate = Worksheets("Data1").Range("Z" &
WorksheetFunction.Match(DateValue(TextBox1.Value),
Worksheets("Data1").Range("Z3:Z600"), 0) + 2)

StartDate declared as a range object.
Dates are in 3/14/01 format.
Textbox1 contains a date
Column Z is a series of dates

When I replace the textbox with a cell to contain the lookup date, the rest
of the program works. So the error can be narrowed to this sub expression:
DateValue(TextBox1.Value)

Thanks for your advice.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default WorksheetFunction.Match

Try

Dim dtTemp as Date
dtTemp = CDate(TextBox1.Text)
Set StartDate = Worksheets("Data1").Range("Z" & _
WorksheetFunction.Match(dtTemp, _
Worksheets("Data1").Range("Z3:Z600").Value, 0) + 2)

OR try the below

Dim dtTemp as Date
dtTemp = CDate(TextBox1.Text)
Msgbox
WorksheetFunction.Match(dtTemp,Worksheets("Data1") .Range("Z3:Z600").Value, 0)

If this post helps click Yes
---------------
Jacob Skaria


"John P" wrote:

Still won't work, Jacob

"Jacob Skaria" wrote:

Try

Set StartDate = Worksheets("Data1").Range("Z" &
WorksheetFunction.Match(DateValue(TextBox1),
Worksheets("Data1").Range("Z3:Z600").Value, 0) + 2)

If this post helps click Yes
---------------
Jacob Skaria


"John P" wrote:

Hi. Can someone please pinpoint the error in this match function statement
using a textbox which contains the lookup date to match a column of dates in
column Z. Program works if I do not use the textbox otherwise it gives a
runtime error:

Set StartDate = Worksheets("Data1").Range("Z" &
WorksheetFunction.Match(DateValue(TextBox1.Value),
Worksheets("Data1").Range("Z3:Z600"), 0) + 2)

StartDate declared as a range object.
Dates are in 3/14/01 format.
Textbox1 contains a date
Column Z is a series of dates

When I replace the textbox with a cell to contain the lookup date, the rest
of the program works. So the error can be narrowed to this sub expression:
DateValue(TextBox1.Value)

Thanks for your advice.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default WorksheetFunction.Match


Using dtTemp = CDate(TextBox1.Text) still gives runtime error. So far, only
using a cell to contain the lookup date makes the program work:
Worksheets("Data1").Range("H2") = TextBox1.Value
I am perplexed as to why this is so.

"Jacob Skaria" wrote:

Try

Dim dtTemp as Date
dtTemp = CDate(TextBox1.Text)
Set StartDate = Worksheets("Data1").Range("Z" & _
WorksheetFunction.Match(dtTemp, _
Worksheets("Data1").Range("Z3:Z600").Value, 0) + 2)

OR try the below

Dim dtTemp as Date
dtTemp = CDate(TextBox1.Text)
Msgbox
WorksheetFunction.Match(dtTemp,Worksheets("Data1") .Range("Z3:Z600").Value, 0)

If this post helps click Yes
---------------
Jacob Skaria


"John P" wrote:

Still won't work, Jacob

"Jacob Skaria" wrote:

Try

Set StartDate = Worksheets("Data1").Range("Z" &
WorksheetFunction.Match(DateValue(TextBox1),
Worksheets("Data1").Range("Z3:Z600").Value, 0) + 2)

If this post helps click Yes
---------------
Jacob Skaria


"John P" wrote:

Hi. Can someone please pinpoint the error in this match function statement
using a textbox which contains the lookup date to match a column of dates in
column Z. Program works if I do not use the textbox otherwise it gives a
runtime error:

Set StartDate = Worksheets("Data1").Range("Z" &
WorksheetFunction.Match(DateValue(TextBox1.Value),
Worksheets("Data1").Range("Z3:Z600"), 0) + 2)

StartDate declared as a range object.
Dates are in 3/14/01 format.
Textbox1 contains a date
Column Z is a series of dates

When I replace the textbox with a cell to contain the lookup date, the rest
of the program works. So the error can be narrowed to this sub expression:
DateValue(TextBox1.Value)

Thanks for your advice.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default WorksheetFunction.Match


If no match is found MATCH will return an error; (like in worksheet formula).
To handle that.

Dim dtTemp as Date
Dim varTemp as variant
Dim rngTemp as range

dtTemp = CDate(TextBox1.Text)
Set rngTemp=Worksheets("Data1").Range("Z3:Z600")
varTemp=Application.match(dtTemp,rngTemp,0)
If IsError(varTemp) then
Msgbox "not found"
Else
Set StartDate = Worksheets("Data1").Range("Z" & varTemp + 2)
End if

If this post helps click Yes
---------------
Jacob Skaria


"John P" wrote:

Using dtTemp = CDate(TextBox1.Text) still gives runtime error. So far, only
using a cell to contain the lookup date makes the program work:
Worksheets("Data1").Range("H2") = TextBox1.Value
I am perplexed as to why this is so.

"Jacob Skaria" wrote:

Try

Dim dtTemp as Date
dtTemp = CDate(TextBox1.Text)
Set StartDate = Worksheets("Data1").Range("Z" & _
WorksheetFunction.Match(dtTemp, _
Worksheets("Data1").Range("Z3:Z600").Value, 0) + 2)

OR try the below

Dim dtTemp as Date
dtTemp = CDate(TextBox1.Text)
Msgbox
WorksheetFunction.Match(dtTemp,Worksheets("Data1") .Range("Z3:Z600").Value, 0)

If this post helps click Yes
---------------
Jacob Skaria


"John P" wrote:

Still won't work, Jacob

"Jacob Skaria" wrote:

Try

Set StartDate = Worksheets("Data1").Range("Z" &
WorksheetFunction.Match(DateValue(TextBox1),
Worksheets("Data1").Range("Z3:Z600").Value, 0) + 2)

If this post helps click Yes
---------------
Jacob Skaria


"John P" wrote:

Hi. Can someone please pinpoint the error in this match function statement
using a textbox which contains the lookup date to match a column of dates in
column Z. Program works if I do not use the textbox otherwise it gives a
runtime error:

Set StartDate = Worksheets("Data1").Range("Z" &
WorksheetFunction.Match(DateValue(TextBox1.Value),
Worksheets("Data1").Range("Z3:Z600"), 0) + 2)

StartDate declared as a range object.
Dates are in 3/14/01 format.
Textbox1 contains a date
Column Z is a series of dates

When I replace the textbox with a cell to contain the lookup date, the rest
of the program works. So the error can be narrowed to this sub expression:
DateValue(TextBox1.Value)

Thanks for your advice.

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
worksheetfunction.match Li Jianyong[_2_] Excel Programming 11 March 10th 10 10:07 PM
Re : Excel VBA and WorkSheetFunction (Match) [email protected] Excel Programming 0 April 10th 08 02:05 AM
Syntax for WorksheetFunction Match Hardy[_3_] Excel Programming 1 June 4th 04 11:33 AM
worksheetfunction.match David Robinson[_3_] Excel Programming 4 November 15th 03 06:35 PM
Worksheetfunction MATCH Yves Janssens Excel Programming 2 October 6th 03 03:25 PM


All times are GMT +1. The time now is 12:11 PM.

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

About Us

"It's about Microsoft Excel"