insert a SEARCH formula in VB

jorgefilemon

New Member
Joined
May 9, 2014
Messages
9
hi guys!


how do i write this in VB

=MID(A1,SEARCH(" ",A1,1)+1,SEARCH(" ",A1,SEARCH(" ",A1,1)+1)-SEARCH(" ",A1,1))


i want to have this formula inside my already created function SKU in VB, I really dont know any VB.




Function SKU(myEntry As String) As String


SKU = Left(myEntry, 3) & _
(THE FORMULA HERE!)
Mid(myEntry, InStr(InStr(myEntry, " ") + 1, myEntry, " ") + 1, 2) & _
Right(myEntry, 2)


End Function
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi Jorge

Code:
Function SKU$(E$)
Dim s
s = Evaluate("=MID(A1,SEARCH("" "",A1,1)+1,SEARCH("" "",A1,SEARCH("" "",A1,1)+1)-SEARCH("" "",A1,1))")
SKU = Left(E, 3) & s & Mid(E, InStr(InStr(E, " ") + 1, E, " ") + 1, 2) & Right(E, 2)
End Function
 
Upvote 0
or:

Code:
Function SKU$(E$)
SKU = Left(E, 3) & _
Evaluate("=MID(A1,SEARCH("" "",A1,1)+1,SEARCH("" "",A1,SEARCH("" "",A1,1)+1)-SEARCH("" "",A1,1))") & _
Mid(E, InStr(InStr(E, " ") + 1, E, " ") + 1, 2) & Right(E, 2)
End Function
 
Upvote 0
hey Worf, thanks for taking ur time and answering my question!, it doesn't quiet work though.

I don't want A1 cell actually, i substituted A1 for the variable E based on ur code, but still didn't work.

i'm only missing this part in my code, the ability to take the whole number from second position in my description column regardless the length of it.

i uploaded a pic, maybe it's clearer this way




 
Upvote 0
This version gets the information from the cell located two columns apart the function cell:

Code:
Function SKU$(E$)
Dim a
a = Range(Application.Caller.Address).Offset(, 2).Address               ' two columns to the right
SKU = Left(E, 3) & Evaluate("=MID(" & a & ",SEARCH("" ""," & a & ",1)+1,SEARCH("" ""," & _
a & ",SEARCH("" ""," & a & ",1)+1)-SEARCH("" ""," & a & ",1))") & _
Mid(E, InStr(InStr(E, " ") + 1, E, " ") + 1, 2) & Right(E, 2)
End Function
 
Upvote 0
hi worf, thanks a lot again!!!.

the code is making a space in the sku(clave) that I don't need though.

that's the only part missing, if you could help me to fix it.. i'll appreciate it tons






This version gets the information from the cell located two columns apart the function cell:

Code:
Function SKU$(E$)
Dim a
a = Range(Application.Caller.Address).Offset(, 2).Address               ' two columns to the right
SKU = Left(E, 3) & Evaluate("=MID(" & a & ",SEARCH("" ""," & a & ",1)+1,SEARCH("" ""," & _
a & ",SEARCH("" ""," & a & ",1)+1)-SEARCH("" ""," & a & ",1))") & _
Mid(E, InStr(InStr(E, " ") + 1, E, " ") + 1, 2) & Right(E, 2)
End Function
 
Upvote 0
Please test this:

Code:
Function SKU$(E$)
Dim a$
a = Range(Application.Caller.Address).Offset(, 2).Address               ' two columns to the right
SKU = Replace(Left(E, 3) & Evaluate("=MID(" & a & ",SEARCH("" ""," & a & ",1)+1,SEARCH("" ""," & _
a & ",SEARCH("" ""," & a & ",1)+1)-SEARCH("" ""," & a & ",1))") & _
Mid(E, InStr(InStr(E, " ") + 1, E, " ") + 1, 2) & Right(E, 2), " ", "")
End Function
 
Upvote 0

Forum statistics

Threads
1,216,216
Messages
6,129,566
Members
449,517
Latest member
Lsmich

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top