?
Solved

add character in correct position in vba

Posted on 2011-03-22
5
Medium Priority
?
211 Views
Last Modified: 2012-05-11
I have two words

hilux  
hi-lux


I have ascertained the position of the hyphen in StringWords2(index2) how do i insert that hyphen into the same position in StringWords1(index)?

I have previously determined that removal of the hyphen would lead to a match of words.

but I want to insert and not remove it.

'traverse array and compare the words
        
    For index = LBound(StringWords1()) To UBound(StringWords1())
    For index2 = LBound(StringWords2()) To UBound(StringWords2())
    
    If Replace(StringWords2(index2), "-", "") = StringWords1(index) Then
  
    hypenPos = InStr(1, StringWords2(index2), "-", vbTextCompare)
    Else
   
    
    End If

Open in new window

0
Comment
Question by:PeterBaileyUk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35192783
Try:
For index = LBound(StringWords1()) To UBound(StringWords1())
    For index2 = LBound(StringWords2()) To UBound(StringWords2())

        If Replace(StringWords2(index2), "-", "") = StringWords1(index) Then

            hypenPos = InStr(1, StringWords2(index2), "-", vbTextCompare)
            
            StringWords1(index) = Mid(StringWords1(index), 1, hyphenPos - 1) & "-" & Mid(StringWords1(index), hyphenPos)
        Else
        
        End If

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 35192912
I get an invalid procedure call on:

StringWords1(index) = Mid(StringWords1(index), 1, hyphenPos - 1) & "-" & Mid(StringWords1(index), hyphenPos)
0
 

Author Comment

by:PeterBaileyUk
ID: 35193058
was a spelling mistake all working
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 35193062
thank u
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35193082
NP. Glad to help  = )
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question