Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Variable Declaration??
the partnumber in checkpartnumber is local to the checkpartnumber routine
because it is in the argument list. Therefore, the Public variable PN is never set. Private Sub Worksheet_Change(ByVal Target As Range) If Target.Count 1 Then Exit Sub If Target = "" Then Exit Sub If Target.Column = 1 And Target.Row 1 Then _ Call CheckPartNumber(Target.Value) End Sub Option Explicit Sub CheckPartNumber(PN) MsgBox "PN is: " & PN ChkLen PN End Sub Sub ChkLen(PN) MsgBox "ChkLen PN is: " & PN MsgBox "Len of PN is: " & Len(PN) End Sub Should work. -- Regards, Tom Ogilvy "Otto Moehrbach" wrote in message ... Excel 2002, Win XP I am making a very basic mistake in the following macros and I can't see it. The first macro simply calls the 2nd macro and passes Target.Value to it. The 2nd macro calls the third macro and that's when things go wrong. Because I am using "PN" in more than one macro, I declared "PN" at the top of the module. I think here is the mistake but I can't see it. Target.Value is a 15 character string. The MsgBox in CheckPartNumber shows that PN is the 15 Chr string. The 2 MsgBox's in ChkLen show that PN is nothing with a length of 0. Question: What happened to the value of PN? Thanks for your help. Otto Private Sub Worksheet_Change(ByVal Target As Range) If Target.Count 1 Then Exit Sub If Target = "" Then Exit Sub If Target.Column = 1 And Target.Row 1 Then _ Call CheckPartNumber(Target.Value) End Sub Option Explicit Dim PN As String Sub CheckPartNumber(PN) MsgBox "PN is: " & PN ChkLen End Sub Sub ChkLen() MsgBox "ChkLen PN is: " & PN MsgBox "Len of PN is: " & Len(PN) End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Array Declaration. | Excel Discussion (Misc queries) | |||
Adding a variable into a range declaration | Excel Worksheet Functions | |||
Workbook Declaration | Excel Discussion (Misc queries) | |||
VBA - variable declaration | Excel Discussion (Misc queries) | |||
type declaration characters | Excel Discussion (Misc queries) |