Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

GETTING CUSTOMER NAME FROM ANOTHER WORKBOOK THRU PUBLIC FUNCTION

  Asked By: Pedro    Date: Dec 12    Category: MS Office    Views: 831
  

I have created a following function, but this is not giving me the desired
result, i want to get customer name from customer master file, with input of
customer code.

please help me out.



Public Function CustomerName(CustomerCode As string) as string


Workbooks.Open Filename:= _
"C:\CUSTOMER\CUSTOMERLIST.XLS"
Worksheets("LIST").Activate
Worksheets("LIST").Range("A1").Select
I = 0
For I = 0 To 200
If Selection.Offset(I, 0).Value = CUSTOMERCODE Then
CUSTOMERNAME = Selection.Offset(I, 1).Value


End If


Next



ActiveWindow.Close



End function

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Kanchan Ap     Answered On: Dec 12

I can't see anything immediately wrong with the code.

What exactly is it doing wrong? What happens when you put a breakpoint on it
and step it through?

 
Answer #2    Answered By: Haya Yoshida     Answered On: Dec 12

What does your DATA look like?
From what I see, the CustomerCODE is in column A
and the Customer NAME is in column B.
in a sheet called " LIST" (with a leading space)
To debug it, put a watch on "selection.offset(i,0).value"
then step through and see what it shows.

 




Tagged: