Conditional change: Change value in a cell based on specific text (ending in "X") in another column

Bob_C

New Member
Joined
Nov 13, 2019
Messages
4
Hello Board,

I am new to board and dumb, hoping someone would share a simple VBA code

I have a large table of data of ~10000 rows.

I'd like VBA Code to loop through:
1) evaluate data in column A for cells that contains 5 characters ending in letter "X"
2) If it finds such, I'd like to change text in column C to "Group"

For Example: In this it would change C2 and C3 to "Group" since A2 and A3 ID#'s contain 5 letters and end in X

ABC
1ID#AMOUNTTYPE
2RBFCX5001
Single
3TLSHX4006Indiv
4VA98278542Single
5UDGSX9865Group

<tbody>
</tbody>



Thanks for any help
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
60,131
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
Code:
Sub BobC()
    With Range("C2:C" & Range("A" & Rows.Count).End(xlUp).Row)
        .Value = Evaluate(Replace("If((len(@)=5)*(right(@)=""X""),""Group""," & .Address & ")", "@", .Offset(, -2).Address))
    End With
End Sub
 

Bob_C

New Member
Joined
Nov 13, 2019
Messages
4
Thanks for replying Fluff! Your code ran without error, unfortunately it did not replace anything in the worksheet.
 

Bob_C

New Member
Joined
Nov 13, 2019
Messages
4
FORGIVE ME FLUFF!!! I happened to add a column while experimenting. When I adjusted range it ran successfully.

Thank you very much!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
60,131
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback
 

Forum statistics

Threads
1,136,792
Messages
5,677,759
Members
419,718
Latest member
ALWP

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
Top