My code crashes Excel - help please

Joined
May 6, 2011
Messages
25
I'm clearly doing something wrong here; I'd love just a quick note as to what it might be.

Sub AddCategories()
Range("G2").Select
Do
If ActiveCell.Font.Color = 153 Then
ActiveCell.Offset(1, 0).Select

ElseIf InStr(1, ActiveCell, "RMC", 0) > 0 Then
ActiveCell.Offset(0, -3) = "RMC"
ActiveCell.Offset(1, 0).Select

ElseIf InStr(1, ActiveCell, "SCP", 0) > 0 Then
ActiveCell.Offset(0, -3) = "SCP"
ActiveCell.Offset(1, 0).Select

ElseIf InStr(1, ActiveCell, "TNC", 0) > 0 Then
ActiveCell.Offset(0, -3) = "TNC"
ActiveCell.Offset(1, 0).Select

ElseIf InStr(1, ActiveCell, "TER", 0) > 0 Then
ActiveCell.Offset(0, -3) = "TER"
ActiveCell.Offset(1, 0).Select

ElseIf InStr(1, ActiveCell, "UMO", 0) > 0 Then
ActiveCell.Offset(0, -3) = "UMO"
ActiveCell.Offset(1, 0).Select

ElseIf InStr(1, ActiveCell, "GD", 0) > 0 Then
ActiveCell.Offset(0, -3) = "GD"
ActiveCell.Offset(0, -2) = "WMD"
ActiveCell.Offset(1, 0).Select

End If
Loop Until IsEmpty(ActiveCell.Offset(0, -6))
End Sub
 
Blade Hunter,

I think I'll take you up on that array explanation offer. I've got a function that works just fine, but it's long, ugly, and hard to expand:

=IF(OR(ISNUMBER(SEARCH(E$3,$A2)),ISNUMBER(SEARCH(E$4,$A2)),ISNUMBER(SEARCH(E$5,$A2)),ISNUMBER(SEARCH(E$6,$A2))),E$2,"")

In other words, if any of the strings I've entered in cells E3 through E6 are found in cell A2, then the contents of E2 are returned in the active cell.

Like I said, this works fine, but it gets ever longer and more unwieldy the more search terms I add.

I know that the answer is an array. How would I go about transforming this into one?

Thanks in advance for your help. If you think I should start a new thread for this, I'd be glad to.
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

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