Results 1 to 3 of 3

Thread: use of mid() in vba

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2001
    Location
    Melbourne, Florida
    Posts
    65

    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

  2. #2
    New Member
    Join Date
    Jun 2003
    Posts
    9
    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))

  3. #3
    New Member
    Join Date
    Dec 2003
    Posts
    2

    Smile 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
  •  



Click Here to Expand Forum to Full Width