I
Ian
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
-------------------------------------------------------------------------
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
-------------------------------------------------------------------------