|
-
Dec 11th, 2003, 12:55 PM
#1
Thread Starter
Lively Member
use of mid() in vba
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
-
Dec 12th, 2003, 08:54 AM
#2
New Member
You need to concatenate the result of two separate Mid function calls to get your desired result..
Something like..
Code:
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))
-
Dec 21st, 2003, 03:25 AM
#3
New Member
Re:
Try to use the replace function as follows:
replace(strname,"FF","")
It'll do the whole job for you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|