Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Worksheet Functions / March 2008

Tip: Looking for answers? Try searching our database.

Find Method problem in Excel VBA....

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Irmann - 27 Feb 2008 07:41 GMT
I have a problem about using find method in Excel VBA.
Here is my program:-
_________________________________________________________________

Private Sub CommandButton2_Click()

Dim MyProduct As Range
Product = Range("F8").Value
Set MyProduct =
ThisWorkbook.Sheets("Sheet2").Columns("E").Find(what:=Client,
LookAt:=xlWhole)

ActiveSheet.Cells(8, 8).Value = MyProduct.Columns("G").Value

End Sub
_____________________________________________________________________

> how can I pull data at Columns(G) to Cells(8,8)
>the program I wrote ' ActiveSheet.Cells(8, 8).Value =
MyClient.Columns("G").Value ' , give me error... Run-time error '91'
Object variable or With block variable not set
>What does it mean?
> Please someone help me to solve this problem....

Signature

Irmann

Bernie Deitrick - 27 Feb 2008 14:01 GMT
Irmann,

Your line

ActiveSheet.Cells(8, 8).Value = MyProduct.Columns("G").Value

uses relative addresssing (this part, psecifically:  MyProduct.Columns("G").Value) , which means
that the code will pull the value from 7 columns to the right of MyProduct (a cell in column E) - so
the value is from column K.  If you really want the value from column G, then use

ActiveSheet.Cells(8, 8).Value = MyProduct.Offset(0,2).Value

HTH,
Bernie
MS Excel MVP

> I have a problem about using find method in Excel VBA.
> Here is my program:-
[quoted text clipped - 19 lines]
>>What does it mean?
>> Please someone help me to solve this problem....
Irmann - 28 Feb 2008 03:55 GMT
Thank You Bernie Deitrick for the reply.

That helping me a lot. :-)

Bernie, can you show me how to program my previous program by using
'For....Next' method.

because i don't want just find Range("F8") only. I want the program ca
looping from Range("F8") to Range("F100") and the same time can pul
difference data.

Below is the new program that i use 'For....next' method(don't know it
right or not) :-

Private Sub CommandButton2_Click()

Dim MyProduct As Range
For i = 7 To 100
Product = Cells(i + 1, 6).Value  'Range("F8") = Cells(8, 6)
Set MyProduct = ThisWorkbook.Sheets("Sheet2").Columns("E").Fin
_(what:=Client, LookAt:=xlWhole)
Next

ActiveSheet.Cells(i + 1, 8).Value = MyProduct.Offset(0, 2).Value

End Sub

Bernie Deitrick;631843 Wrote:
> Irmann,
>
[quoted text clipped - 39 lines]
> >>What does it mean?
> >> Please someone help me to solve this problem....-

--
Irmann
Bernie Deitrick - 28 Feb 2008 14:55 GMT
Irmann,

This is how you would loop.  I changed the item being found from Client to Product - otherwise, you
would simply find the same thing each time.  I'm not sure if that is what you want, but you should
be able to get the idea....

Dim MyProduct As Range
For i = 8 To 100
    Product = Cells(i, 6).Value  'Range("F8") = Cells(8, 6)
    Set MyProduct = ThisWorkbook.Sheets("Sheet2").Columns("E").Find _
       (what:=Product, LookAt:=xlWhole)
    Cells(i, 8).Value = MyProduct.Offset(0, 2).Value
Next i

Without looping:

With Range("H8:H100")
   .Formula = "=INDEX(Sheet2!G:G,MATCH(F8,Sheet2!E:E,False))"
   .Value = .Value
End With

HTH,
Bernie
MS Excel MVP

> Thank You Bernie Deitrick for the reply.
>
[quoted text clipped - 67 lines]
>> >>What does it mean?
>> >> Please someone help me to solve this problem....-
Irmann - 03 Mar 2008 06:24 GMT
Thanks Bernie,

The program you give it to me run smoothly. The program run(looping) i
= 8 To 100. It find the same name(product) in sheet1 at sheet2. When it
find the same product name at sheet2, it pull data at column 'E' to
Cells(i, 8) in sheet1. The problem is, when it can't find the same
product name, the program give me error like it can't jump to the Next
i.  

Bernie, what is the program that can jump to the Next i after it can't
find the same product name.

### Bernie can you give me your email address. I want give you my excel
file.

Thanks,

IRmann

Bernie Deitrick;632349 Wrote:
> Irmann,
>
[quoted text clipped - 99 lines]
> >> >>What does it mean?
> >> >> Please someone help me to solve this problem....-

Signature

Irmann

Bernie Deitrick - 03 Mar 2008 13:59 GMT
Irmann,

To check that the value is actually found before processing:

For i = 8 To 100
    Product = Cells(i, 6).Value  'Range("F8") = Cells(8, 6)
    Set MyProduct = ThisWorkbook.Sheets("Sheet2").Columns("E").Find _
       (what:=Product, LookAt:=xlWhole)
    If Not MyProduct Is Nothing Then Cells(i, 8).Value = MyProduct.Offset(0, 2).Value
Next i

HTH,
Bernie
MS Excel MVP

> Thanks Bernie,
>
[quoted text clipped - 119 lines]
>> >> >>What does it mean?
>> >> >> Please someone help me to solve this problem....-
Irmann - 04 Mar 2008 09:14 GMT
Thank You so much Bernie for the code you gave it to me..... Its reall
helps. ;-) . Thanks again so so much.

>>I got one more question to ask you. Before this, we discuss th
coding that can pull data between two difference sheet in the sam
workbook using Find method. Can we do it with difference workbook?
>>can you give me the code........... i'm try to do it by myself but i
give me an error.

thanks,

IRmann

Bernie Deitrick;633856 Wrote:
> Irmann,
>
[quoted text clipped - 149 lines]
> >> >> >>What does it mean?
> >> >> >> Please someone help me to solve this problem....-

Signature

Irmann

Irmann - 10 Mar 2008 04:49 GMT
Thank you Bernie Deitrick for helping me solve my excel VBA question and
give me some ideal. Thanks again.. God bless you

I’m try to automated 3 excel file that can pull some data by using Find
method. The coding succeeds. Below is the coding:-

Private Sub CommandButton2_Click()

Dim MyProduct As Range

For i = 5 To 100
Product = Cells(i, 6).Value  'Range("F8") = Cells(8, 6)
Set MyProduct = Workbooks("January KLM NPI
ReviewIR.xls").Worksheets("Sheet1").Columns("E").Find(what:=Product,
LookAt:=xlWhole)
If Not MyProduct Is Nothing Then Cells(i, 8).Value =
MyProduct.Offset(0, 4).Value
If Not MyProduct Is Nothing Then Cells(i, 17).Value =
MyProduct.Offset(0, 6).Value
Next i

End Sub

This thread SOLVE

Signature

Irmann

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.