Edit String dependent on first word

DenialDan

New Member
Joined
May 31, 2017
Messages
15
I'm trying cut all the words of a string except the first one and paste the resulting "new" string in the cell where the old one was. This is the code I came up with so far:

Code:
Sub CECorrect()


Dim i As Integer
Dim s As String
Dim indexOfString As Integer
Dim finalString As String


For i = 4 To 10000


    s = Sheets("Sheet Name").Cells(i, 31).Value ' the first string is at AE4
    indexOfString = InStr(1, s, "Strong") ' the word to be extracted here is "Strong"
    finalString = Left(s, Len(s) - indexOfString + 1)
    
    Sheets("Sheet Name").Cells(i, 31) = finalString
    
Next i


End Sub

Just some sidenotes:
  • cells (i.e. AE4) can be empty, the data changes weekly, tell me if that's a problem
  • "Strong" isn't the only word I need extracted, the others are "Moderate" and "Weak" but they are all in the same column
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
if you choose to detect the left 4 characters as uppercase, WEAK, STRO, MODE then you could use something to replace the Cell contents

=UPPER(LEFT(Cell contents,4) = onwards
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

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