Instring Ucase Shorten Procedure

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,060
I have the following macro to change a part of a cell if a value is found.

i.e cell value (Help) maybe either of the following 3 examples
Help, help, HELP

Remember there is also text before and after the help value i.e.
123Helpabc

My question is, can someone help with an abbreviated script so that it cuts it down and therefore when I change the script in the future it is easier.

The script I currently use is

Code:
Sub test3()
Range(Cells(Rows.Count, "A").End(xlUp), Cells(2, "A")).Select
For Each Cell In Selection
If InStr(Cell.Value, "HELP") > 0 Then
Cell.Value = Mid(Cell.Value, InStr(Cell.Value, "HELP"), 4)
Else
If InStr(Cell.Value, "Help") > 0 Then
Cell.Value = Mid(Cell.Value, InStr(Cell.Value, "Help"), 4)
Else
If InStr(Cell.Value, "help") > 0 Then
Cell.Value = Mid(Cell.Value, InStr(Cell.Value, "help"), 4)
End If
End If
End If
Next Cell
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try
Code:
Sub test()
    Dim Cell As Range, Rng As Range
    Set Rng = Range(Cells(Rows.Count, "A").End(xlUp), Cells(2, "A"))
    For Each Cell In Rng
        If InStr(1, Cell.Value, "HELP", vbTextCompare) > 0 Then
            Cell.Value = Mid(Cell.Value, InStr(1, Cell.Value, "help", vbTextCompare), 4)
        End If
    Next Cell
    
    'Release memory
    Set Rng = Nothing
    
End Sub

Biz
 
Upvote 0

Forum statistics

Threads
1,215,475
Messages
6,125,028
Members
449,205
Latest member
Eggy66

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