VBA Looping Find text within string help needed

cb12

Board Regular
Joined
Dec 20, 2008
Messages
117
Evening,

I have had a look through previous htreads but seem unable to find an appropriate solution so thought I would create a new thread.

I have c.20,000 rows and in column I there is data along the format of (for example) "Date: October 21st / xxxxxxxxxxxxxxxxxxxxxx" where the xxxxx could be any number of characters.

I want to be able to remove the "Date: October 21st / " without having to create 365 find and replaces.

I'm currently using the procedure:

Code:
Sub Month_Remover()
    
    Dim MyString As String
    Dim StringLen, Pos As Integer
    Dim Result As Variant

    MyString = ActiveCell
    StringLen = Len(MyString)
    Pos = StringLen - 20
    Result = Right(MyString, Pos)
    
        ActiveCell.Value = Result
        ActiveCell.Offset(1, 0).Select

End Sub

However I'm having problems cycling it through the data (without it looping constantly through the spreadsheet until it crashes). Does anyone have any ideas on how I might do this more efficiently? Any help will be most welcome.

One other thing the line "Pos = StringLen - 20" would obviously have to changed for each month but I would be happy to have 12 different iterations rather than 365.

Regards

CB
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I would use this formula and find a way to incorporate it into the VBA code.

=LEFT(G15,FIND("/",G15))
 
Upvote 0
Thank you - a new perspective always helps.

I have edited the code so it will read something along the lines of

Code:
Sub Month_Remover()
Dim MyString As String
Dim StringLen As Integer
Dim Pos As Integer
Dim result As Variant

    MyString = ActiveCell
    StringLen = Len(MyString)
    Pos = StringLen - ActiveCell.Offset(0, 10).Value
    result = Right(MyString, Pos)

    ActiveCell.Value = result
        ActiveCell.Offset(1, 0).Select
    
End Sub

where ActiveCell.Offset(0, 10).Value will equal =FIND("/",I10) or the relevant row.

Probably not ideal but it'll keep me going for now. Thank you.

Edit: I'm sure there's a way to mark the thread as completed but I can't see where.
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,818
Members
452,946
Latest member
JoseDavid

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