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
Solved

add character in correct position in vba

Posted on 2011-03-22
5
206 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
  • 3
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

856 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