PC Review


Reply
Thread Tools Rate Thread

Custom Format use with MATCH function

 
 
Enz
Guest
Posts: n/a
 
      17th Nov 2008
Hello,

I am coding a macro that accepts an input file with a date in Custom
format "dd-mmm". Example of content is "01/10/2008" which appears as
"01-Oct". Within the macro I have tab with columns labelled with
Custom Format "mmm-yyyy", example "Oct-2008", "Nov-2008" that I would
like to populate with data from the input file.

I have tried to convert the input date in several ways into for
example into "Oct-2008", then using the MATCH(convertedDate, range
within the sheet, 0), to find the column to populate with other input
data.

This unfortunately always produced the "error 2042" error message. I
have checked and the input file date is in date format, and I have
double checked the columns to ensure they are in a Custom Format also
that is a date, and they are.

Is there a better/more efficient way to perform this?

This is a version I have here does not work as lMonthYear2 is not
converting properly, but I am more interested in finding the best way
to do the search I am interested in doing based on the nature of the
input data.

lMonthYear = CDate(WWExtractInput.Worksheets(1).Cells(2, 6).Value)
lMonthYear2 = Format(lMonthYear, "mmm-yyyy")
lTeamYTDColumnTemp = Application.Match(lMonthYear2,
wsTeamYTDTab.Range("D2:P2"), 0)

Your assistance is much appreciated.

regards,
Enzo
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      17th Nov 2008
You don't need to convert to a string for the match function. You should be
using the serial date. You may have problems with matching if the date
(Oct-2008) is not the first of the month. When you are displaying Oct-2008
it can be any day of the month

First try this. Note CDate shouldn't be required unless you have a sttring

lMonthYear = WWExtractInput.Worksheets(1).Cells(2, 6).Value
lTeamYTDColumnTemp = _
Application.Match(lMonthYear,wsTeamYTDTab.Range("D2:P2"), 0)

Second try this

lMonthYear = WWExtractInput.Worksheets(1).Cells(2, 6).Value
lMonthYear2 = DateSerial(year(lMonthYear),month(lMonthYear),1)
lTeamYTDColumnTemp = _
Application.Match(lMonthYear2,wsTeamYTDTab.Range("D2:P2"), 0)

If neither works then the dates in D2:P2 and not serial dates or not the 1st
of the month and should be fixed.


"Enz" wrote:

> Hello,
>
> I am coding a macro that accepts an input file with a date in Custom
> format "dd-mmm". Example of content is "01/10/2008" which appears as
> "01-Oct". Within the macro I have tab with columns labelled with
> Custom Format "mmm-yyyy", example "Oct-2008", "Nov-2008" that I would
> like to populate with data from the input file.
>
> I have tried to convert the input date in several ways into for
> example into "Oct-2008", then using the MATCH(convertedDate, range
> within the sheet, 0), to find the column to populate with other input
> data.
>
> This unfortunately always produced the "error 2042" error message. I
> have checked and the input file date is in date format, and I have
> double checked the columns to ensure they are in a Custom Format also
> that is a date, and they are.
>
> Is there a better/more efficient way to perform this?
>
> This is a version I have here does not work as lMonthYear2 is not
> converting properly, but I am more interested in finding the best way
> to do the search I am interested in doing based on the nature of the
> input data.
>
> lMonthYear = CDate(WWExtractInput.Worksheets(1).Cells(2, 6).Value)
> lMonthYear2 = Format(lMonthYear, "mmm-yyyy")
> lTeamYTDColumnTemp = Application.Match(lMonthYear2,
> wsTeamYTDTab.Range("D2:P2"), 0)
>
> Your assistance is much appreciated.
>
> regards,
> Enzo
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Format or use function? Lisa W Microsoft Excel Worksheet Functions 4 21st Jul 2009 06:06 PM
Match & Index function - Cell format problem that is keeping it fromworking for me Mike C Microsoft Excel Discussion 5 10th Mar 2008 12:54 AM
Custom function to simplify Index(match)) formula =?Utf-8?B?TWFydGlu?= Microsoft Excel Misc 0 20th Mar 2006 02:45 PM
Emulate Index/Match combo function w/ VBA custom function =?Utf-8?B?U3BlbmNlciBIdXR0b24=?= Microsoft Excel Worksheet Functions 2 2nd May 2005 05:26 PM
vlookup, IF or Match? or is a custom function required? =?Utf-8?B?Um9iIEJvdXJyaWFndWU=?= Microsoft Excel Worksheet Functions 1 18th Mar 2004 11:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:20 PM.