View Single Post
 
Old 09-30-2024, 07:44 AM
Jakov93 Jakov93 is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jul 2021
Posts: 51
Jakov93 is on a distinguished road
Default Duplicate selected words for continuous and individual selection

Hi,
I made a macro to duplicate selected words according to its sequence in a sentence
Code:
Sub DuplicateSelectedWords()
    
Dim oRng As range
    If Len(Selection.range) = 0 Then
        MsgBox "Select the text first", vbCritical
        Exit Sub
    End If
    Set oRng = Selection.range
    oRng.Copy
    oRng.InsertAfter (oRng.text)

End Sub
It works fine for continues selection, but not for individual selection, which I mean selecting random word (by using Ctrl) in a sentence then duplicate it by run the macro
For individual selection, it just duplicate only one word, may be the first word or second or the last.
So please how to edit the current macro to duplicate all selected words ( individual selection) also.
Thanks
Reply With Quote