PDA

Click to See Complete Forum and Search --> : use of mid() in vba


Cole Patzman
Dec 11th, 2003, 11:55 AM
I'm in VBA and what I am trying to do is to see if the value of "FF" is contained in the text of a cell. The instr() function works fine and comes out with the position. But when I want to delete that value from the cell, or memory variable, I get an error with Mid( highlighted and the error message is wrong number of arguments, or invalid property assignment. The following is the code:
Dim pc As String
Dim ppc As Integer
pc = "FF"
Range("r" & row).Select
Selection.Interior.ColorIndex = 35 'green
If Not IsNumeric(Selection.Text) Then
ppc = InStr(Selection.Text, pc) 'this works fine
Dim positio As String
positio = Selection.Text 'this works fine
While ppc <> 0
positio = Mid(positio, 1, (ppc - 1) & positio, ppc + 2) '
ppc = InStr(Selection.Text, pc)
Wend
endif

Thanks in advance,
Cole
:(

federal102
Dec 12th, 2003, 07:54 AM
You need to concatenate the result of two separate Mid function calls to get your desired result..

Something like..


Dim find_str as String
Dim search_str as String
Dim pos as Long
search_str = "SFFC"
find_str = "FF"
pos = InStr(search_str, find_str)
Dim result as String
result = Mid(search_str, 1, pos - 1) + Mid(search_str, pos, Len(find_str))

yahyamahfouz
Dec 21st, 2003, 02:25 AM
Try to use the replace function as follows:
replace(strname,"FF","")
It'll do the whole job for you