LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Format Vlookup column with Text

Hi
I have the following Macro which uses Vlookup that looks up a Part Number entered in Column A
and returns the correct Part Description in Column C, along with the date the job was booked in,
in Column F, and the date the job is due back (10 days time) in Column G.

The Macro has been working well for the last week or so but now a new problem has risen.
One of the companies has now started sending in repair work with Part Numbers starting with a zero,
so when we enter the Part Number of say "0123456" and press the Enter key, it gets shortened to "123456".
For the Vlookup Macro to work, I have formatted Columns A and C to "General", which is now knocking
of the leading zero's for these new Part Numbers.
If I format Column A to "Text" so it will not knock off the leading zero's, then the Vlookup macro
doesn't run properly and returns "#N/A" for Part Numbers that are already in the DATABASE worksheet.

Is there a way I can format Column A so that it won't delete the leading zero's in a Part Number, and
Vlookup will still work in Column C.

The Macro I am using is as follows:
-------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 And Target.Column = 1 Then
With Range("F" & Target.Row)
.Value = Date
.NumberFormat = "dd/mm/yy"
End With

With Range("G" & Target.Row)
.Value = Date + 10
.NumberFormat = "dd/mm/yy"
End With

With Range("C" & Target.Row)
.Formula = "=IF($A" & Target.Row & "="""","""",VLOOKUP($A" & _
Target.Row & "," & "DATABASE!$A$2:$B$1000,2,FALSE))"
Range("C" & Target.Row).Value = Range("C" & Target.Row).Value
End With
End If
End Sub
-------------------------------------------------------------------------


 
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
Vlookup,format general, format text techguy99 New Users to Excel 2 April 10th 09 01:35 AM
vlookup 1st column time 2nd column text Kathl Excel Worksheet Functions 12 August 12th 08 05:30 AM
Vlookup where table array is in text format jodieg Excel Worksheet Functions 4 January 3rd 08 07:44 PM
how to format numbers stored as text or vice versa to use vlookup teneagle Excel Worksheet Functions 1 February 3rd 05 10:41 PM
Column format as Text Bruce Roberson[_5_] Excel Programming 3 February 14th 04 02:08 AM


All times are GMT +1. The time now is 07:21 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"