![]() |
|
|
|
#1
|
||||
|
||||
|
I can only reply based on the information you provide, however the following should now work with the additional examples.
Code:
Sub Macro1()
'Graham Mayor - https://www.gmayor.com - Last updated - 30 Nov 2018
Dim oRow As Row
Dim oRng As Range
Dim iStart As Integer, iEnd As Integer, i As Integer
Dim strStart As String, strEnd As String
Dim strText As String, strText2 As String
On Error GoTo err_Handler
For Each oRow In Selection.Tables(1).Rows
strText = ""
Set oRng = oRow.Cells(1).Range
oRng.End = oRng.End - 1
oRng.Text = Replace(oRng.Text, "><", ">-<")
If InStr(1, oRng.Text, ">-<") > 0 Then
strStart = Split(oRng.Text, "-")(0)
iStart = NumberFromText(strStart)
strEnd = Split(oRng.Text, "-")(1)
iEnd = NumberFromText(strEnd)
For i = iStart To iEnd
strText = strText & Replace(Split(oRng.Text, "-")(0), CStr(iStart), i)
If i < iEnd Then strText = strText & Chr(11)
Next i
oRng.Text = strText
End If
DoEvents
Next oRow
lbl_Exit:
Set oRng = Nothing
Set oRow = Nothing
Exit Sub
err_Handler:
Err.Clear
GoTo lbl_Exit
End Sub
Function NumberFromText(sText As String) As Integer
Dim Length_of_String As Integer
Dim iPos As Integer
Dim strNum As String
On Error GoTo err_Handler
Length_of_String = Len(sText)
For iPos = 1 To Length_of_String
If (IsNumeric(Mid(sText, iPos, 1))) = True Then
strNum = strNum & Mid(sText, iPos, 1)
End If
Next iPos
If Len(strNum) = 0 Then
NumberFromText = 0
Else
NumberFromText = CInt(strNum)
End If
lbl_Exit:
Exit Function
err_Handler:
NumberFromText = 0
Err.Clear
GoTo lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#2
|
|||
|
|||
|
Yes. Its my fault.
This one is awesome as i expected. Many thanks again!!!! |
|
#3
|
|||
|
|||
|
Hi gmayor
Sorry for the inconvenience... This one is changing all the occurrences like even if its without the hyphens as follows: <fir fin=“MP5“/><fir fin=“MP7“/>, <fir fin=“MP6“/><fir fin=“MP7“/> .... they are also in the same rows. Only needs to be expand hyphenated values and others are needs to be retained. Please advise. |
|
#4
|
||||
|
||||
|
I assumed that the missing hyphens were typos
![]() Remove the line Code:
oRng.Text = Replace(oRng.Text, "><", ">-<")
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#5
|
|||
|
|||
|
After removed the above line it's taken off all the contents!!!
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Need macro to fill the values in msword based on the excel sheet info
|
ganesang | Word VBA | 50 | 08-29-2018 12:53 AM |
Table with values from several locations and years - need to find comp values
|
Ricardo Sousa | Excel | 6 | 06-09-2018 10:51 PM |
Macro to Find & Replace Font formats for Multiple Values
|
GemBox | Word | 6 | 03-12-2018 05:24 AM |
| Macro to Expand Outline Heading in Outline View? | Clueless in Seattle | Word VBA | 1 | 05-04-2015 05:44 PM |
macro to find a character and insert space so autocorrect will expand
|
redzan | Word VBA | 3 | 05-22-2014 04:22 PM |