[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

add character in correct position in vba

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
PeterBaileyUk
Asked:
PeterBaileyUk
  • 3
  • 2
1 Solution
 
käµfm³d 👽Commented:
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
 
PeterBaileyUkAuthor Commented:
I get an invalid procedure call on:

StringWords1(index) = Mid(StringWords1(index), 1, hyphenPos - 1) & "-" & Mid(StringWords1(index), hyphenPos)
0
 
PeterBaileyUkAuthor Commented:
was a spelling mistake all working
0
 
PeterBaileyUkAuthor Commented:
thank u
0
 
käµfm³d 👽Commented:
NP. Glad to help  = )
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now