Solved

add character in correct position in vba

Posted on 2011-03-22
5
203 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 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
I get an invalid procedure call on:

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

Author Comment

by:PeterBaileyUk
Comment Utility
was a spelling mistake all working
0
 

Author Closing Comment

by:PeterBaileyUk
Comment Utility
thank u
0
 
LVL 74

Expert Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now