Stripping out regex strings out of a range

sdspieg

Board Regular
Joined
Dec 9, 2013
Messages
98
2805085 (1).xlsm
NOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJBKBLBMBNBOBPBQBRBSBTBUBVBWBXBYBZCACBCCCDCECFCGCHCICJCKCLCMCNCOCPCQCRCSCTCUCVCWCXCYCZDADBDCDDDEDFDGDHDI
3Q6.1.1. Future Russia - Putinism foreverQ6.1.2. Future Russia - RaspadQ6.1.3. Future Russia - (Re-?) Turn to EuropeQ6.1.4. Future Russia - Stalinism on AI SteroidsQ6.2.1. Future Russia - Putinism foreverQ6.2.2. Future Russia - RaspadQ6.2.3. Future Russia - (Re-?) Turn to EuropeQ6.2.4. Future Russia - Stalinism on AI SteroidsQ6.3.1. Future Russia - Putinism foreverQ6.3.2. Future Russia - RaspadQ6.3.3. Future Russia - (Re-?) Turn to EuropeQ6.3.4. Future Russia - Stalinism on AI SteroidsQ6.4.1. Future Russia - Putinism foreverQ6.4.2. Future Russia - RaspadQ6.4.3. Future Russia - (Re-?) Turn to EuropeQ6.4.4. Future Russia - Stalinism on AI SteroidsQ6.5.1. Future Russia - Putinism foreverQ6.5.2. Future Russia - RaspadQ6.5.3. Future Russia - (Re-?) Turn to EuropeQ6.5.4. Future Russia - Stalinism on AI SteroidsQ6.6.1. Future Russia - Putinism foreverQ6.6.2. Future Russia - RaspadQ6.6.3. Future Russia - (Re-?) Turn to EuropeQ6.6.4. Future Russia - Stalinism on AI SteroidsQ7.1.1. Diplomatic engagementQ7.1.2. Economic engagement (positive and/or negative stimuli)Q7.1.3. Targeted information outreachQ7.2.1. Diplomatic engagementQ7.2.2. Economic engagement (positive and/or negative stimuli)Q7.2.3. Targeted information outreachQ7.3.1. Diplomatic engagementQ7.3.2. Economic engagement (positive and/or negative stimuli)Q7.3.3. Targeted information outreachQ7.4.1. Diplomatic engagementQ7.4.2. Economic engagement (positive and/or negative stimuli)Q7.4.3. Targeted information outreachQ7.5.1. Diplomatic engagementQ7.5.2. Economic engagement (positive and/or negative stimuli)Q7.5.3. Targeted information outreachQ7.6.1. Diplomatic engagementQ7.6.2. Economic engagement (positive and/or negative stimuli)Q7.6.3. Targeted information outreachQ7.7.1. Diplomatic engagementQ7.7.2. Economic engagement (positive and/or negative stimuli)Q7.7.3. Targeted information outreachQ8.1.1. Acceptability for EuropeQ8.1.2. Desirability for EuropeQ8.1.3. Receptiveness of the Russian 'targets'Q8.1.4. Expected effectivenessQ8.2.1. Acceptability for EuropeQ8.2.2. Desirability for EuropeQ8.2.3. Receptiveness of the Russian 'targets'Q8.2.4. Expected effectivenessQ8.3.1. Acceptability for EuropeQ8.3.2. Desirability for EuropeQ8.3.3. Receptiveness of the Russian 'targets'Q8.3.4. Expected effectivenessQ8.4.1. Acceptability for EuropeQ8.4.2. Desirability for EuropeQ8.4.3. Receptiveness of the Russian 'targets'Q8.4.4. Expected effectivenessQ8.5.1. Acceptability for EuropeQ8.5.2. Desirability for EuropeQ8.5.3. Receptiveness of the Russian 'targets'Q8.5.4. Expected effectivenessQ8.6.1. Acceptability for EuropeQ8.6.2. Desirability for EuropeQ8.6.3. Receptiveness of the Russian 'targets'Q8.6.4. Expected effectivenessQ8.7.1. Acceptability for EuropeQ8.7.2. Desirability for EuropeQ8.7.3. Receptiveness of the Russian 'targets'Q8.7.4. Expected effectivenessQ9.1.1. ImmediatelyQ9.1.2. Medium-termQ9.1.3. Long-termQ9.2.1. ImmediatelyQ9.2.2. Medium-termQ9.2.3. Long-termQ9.3.1. ImmediatelyQ9.3.2. Medium-termQ9.3.3. Long-termQ9.4.1. ImmediatelyQ9.4.2. Medium-termQ9.4.3. Long-termQ9.5.1. ImmediatelyQ9.5.2. Medium-termQ9.5.3. Long-termQ10.1.1. 2025Q10.1.2. 2030Q10.1.3. 2040Q10.2.1. 2025Q10.2.2. 2030Q10.2.3. 2040Q10.3.1. 2025Q10.3.2. 2030Q10.3.3. 2040Q10.4.1. 2025Q10.4.2. 2030Q10.4.3. 2040
Export + Quant-Likert - Qs


I am trying to strip all strings like "Q8. ", "Q10.2. " or "Q7.4.2 " out of range of cells like the ones I'm sharing here.

I tried this, but it didn't do anything
VBA Code:
Sub RemoveRegexStrings()
    Dim rng As Range
    On Error Resume Next
    Set rng = Application.Selection
    On Error GoTo 0
    If rng Is Nothing Then
        Set rng = Application.InputBox("Please select the range:", Type:=8)
    End If

    Dim cell As Range
    For Each cell In rng
        cell.Value = Trim(Replace(cell.Value, "Q[0-9]*(\.[0-9]*)*\.", ""))
        Next cell
End Sub
As always, dear MrExcel wizards: Help!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
If the only dots in your text occurs in the Q-number at the beginning of the text, and nowhere else, then you can do what you want without using a macro. Select all the cells you want to do this to, press CTRL+H to bring up the Replace dialog box, put this...

Q*. <== Note there is a single space character after the dot

in the "Find what" field, leave the "Replace with" field empty, and then click the "Replace All" button.
 
Upvote 0
If the only dots in your text occurs in the Q-number at the beginning of the text, and nowhere else, then you can do what you want without using a macro. Select all the cells you want to do this to, press CTRL+H to bring up the Replace dialog box, put this...

Q*. <== Note there is a single space character after the dot

in the "Find what" field, leave the "Replace with" field empty, and then click the "Replace All" button.
Thanks Rick. That is - alas, not the case though. I only shared a small part of the spreadsheet, but other parts do have dots. But surely this should be regexable, no?
 
Upvote 0
Thanks Rick. That is - alas, not the case though. I only shared a small part of the spreadsheet, but other parts do have dots. But surely this should be regexable, no?
I do not do RegEx coding, so I cannot help on that part; however, this replacement for your For..Next loop should make your code do what you want...
VBA Code:
  For Each Cell In Selection
    If Cell.Value Like "Q#*. *" Then Cell.Value = Mid(Cell.Value, InStr(Cell.Value, ". ") + 2)
  Next
 
Upvote 0
Solution

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top