![]() |
|
#7
|
|||
|
|||
|
Right, having checked the formula it was never going to work as it replaces all dashes.
My fault, but does show the value of adding in example data. So the next attempt, a UDF Code:
Dim DashNumber As Integer
'Countnumber of dashes for the loop
CountDash = Len(SelectedText) - Len(Replace(SelectedText, Delimit, ""))
'Set output text to start
OutputText = SelectedText
DashNumber = 0
'Loop through all dashes
For I = 1 To CountDash
'Find Dash number in string
DashNumber = InStr(DashNumber + 1, OutputText, Delimit)
'Check char before dash
TextBefore = Mid(OutputText, DashNumber - 1, 1)
'Check char after dash
TextAfter = Mid(OutputText, DashNumber + 1, 1)
'check if before and after chars are equal to space
If TextBefore <> " " And TextAfter <> "" Then
'set outputext as the first chars and then the new text with 1 less dash
OutputText = Mid(OutputText, 1, DashNumber - 1) & Replace(OutputText, Delimit, "", Start:=DashNumber, Count:=1)
End If
Next I
RemoveDash = OutputText
End Function
Last edited by Purfleet; 10-07-2020 at 12:48 PM. Reason: typo |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Search and replace, with paragraphs and wildcards
|
alex100 | Word VBA | 3 | 05-16-2020 08:43 AM |
Search and replace wildcards
|
eduzs | Word VBA | 2 | 06-29-2019 03:01 AM |
Need Search and Replace Help w Wildcards
|
Oberstfunster | Word | 2 | 12-06-2018 09:28 AM |
| Wildcards used for Search and Replace | ChrisRick | Word | 2 | 03-09-2017 05:01 AM |
Search with wildcards
|
imag | Word | 1 | 11-05-2014 11:42 PM |