Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 239
Default How to search in VBA?

I am creating a UDF where I have to retrive one matching value.
My part no comprises of a commen string and 6 variable string.
This makes 6 combinations out of which only one is found in the master
sheet.
I want to know which one is found in master sheet.

Here is a example.
Common Variable Final
L34251154 0024 L3425110024
L34251154 2549 L3425112549
L34251154 5074 L3425115074
L34251154 7599 L3425117599
L34251154 0049 L3425110049
L34251154 5099 L3425115099

I have to test all 6 final strings to findout which one is in master.

So far I have following which is not working.

Option Base 1
Function VV(SER As Range, DUMP As Range)
Dim LT(6) As Variant
If SER.Count < 1 Then End

Series = Left(SER.Value, 7)

LT(1) = Series & "0024"
LT(2) = Series & "2549"
LT(3) = Series & "5074"
LT(4) = Series & "7599"
LT(5) = Series & "0049"
LT(6) = Series & "5099"

For I = 1 To 6
Debug.Print LT(I)
Debug.Print "I= " & I
With DUMP
' Set C = .Find(LT(I), LookIn:=xlValues).Value
Set C = .Find(What:=LT(I).Value, After:=ActiveCell,
LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate


If Not C Is Nothing Then
firstAddress = C.Address
VV = C.Value
End If
End With
Debug.Print "VV= " & VV
Next

End Function

Request if someone can point out my mistake please.

Regards,
Madiya
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How to search in VBA?

There are a couple of issues in your code.

1. Remove the .Activate from your find something like this

Set C = .Find(What:=LT(I).Value, _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=False)
2. You are not doing a findNext so you do not need FirstAddress
3. You can exit the loop with an exit for when you have found a match.

All of that being said it would be a shorter and easier function to do a
CountIf to determine if there is a matching entry. Just my 2 cents.
--
HTH...

Jim Thomlinson


"Madiya" wrote:

I am creating a UDF where I have to retrive one matching value.
My part no comprises of a commen string and 6 variable string.
This makes 6 combinations out of which only one is found in the master
sheet.
I want to know which one is found in master sheet.

Here is a example.
Common Variable Final
L34251154 0024 L3425110024
L34251154 2549 L3425112549
L34251154 5074 L3425115074
L34251154 7599 L3425117599
L34251154 0049 L3425110049
L34251154 5099 L3425115099

I have to test all 6 final strings to findout which one is in master.

So far I have following which is not working.

Option Base 1
Function VV(SER As Range, DUMP As Range)
Dim LT(6) As Variant
If SER.Count < 1 Then End

Series = Left(SER.Value, 7)

LT(1) = Series & "0024"
LT(2) = Series & "2549"
LT(3) = Series & "5074"
LT(4) = Series & "7599"
LT(5) = Series & "0049"
LT(6) = Series & "5099"

For I = 1 To 6
Debug.Print LT(I)
Debug.Print "I= " & I
With DUMP
' Set C = .Find(LT(I), LookIn:=xlValues).Value
Set C = .Find(What:=LT(I).Value, After:=ActiveCell,
LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate


If Not C Is Nothing Then
firstAddress = C.Address
VV = C.Value
End If
End With
Debug.Print "VV= " & VV
Next

End Function

Request if someone can point out my mistake please.

Regards,
Madiya

Reply
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
Functions (search within search result) reply to this please Nick Excel Worksheet Functions 1 February 17th 09 03:57 AM
Search lastname + firstname (search on uppercase) Fr. Vandecan Excel Programming 2 April 8th 07 03:11 PM
How do I search excel spreadsheets using multiple search criteria. Kasper Excel Worksheet Functions 4 December 15th 05 12:26 AM
I cant do a search on this forum. Everytime I search, it comes up with zero results viswanthank Excel Programming 3 June 10th 05 09:15 AM
Create a search Field within a worksheet to search command buttons Ed P[_2_] Excel Programming 1 December 14th 04 08:04 PM


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