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

[TABLE="class: grid, width: 100"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]ID#[/TD]
[TD]AMOUNT[/TD]
[TD]TYPE[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]RBFCX[/TD]
[TD]5001
[/TD]
[TD]Single[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]TLSHX[/TD]
[TD]4006[/TD]
[TD]Indiv[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]VA9827[/TD]
[TD]8542[/TD]
[TD]Single[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]UDGSX[/TD]
[TD]9865[/TD]
[TD]Group[/TD]
[/TR]
</tbody>[/TABLE]



Thanks for any help
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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
 
Upvote 0
Thanks for replying Fluff! Your code ran without error, unfortunately it did not replace anything in the worksheet.
 
Upvote 0
FORGIVE ME FLUFF!!! I happened to add a column while experimenting. When I adjusted range it ran successfully.

Thank you very much!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,735
Messages
6,180,636
Members
452,992
Latest member
TokugawaIesuma

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