Launching Macro Based on Selected Cell Value (first two characters?)

Shiremaid

Board Regular
Joined
Jun 18, 2013
Messages
73
Ok, so I have a macro to sort a very large list of materials by a variety of conditions.
The macro runs automatically when a cell on the master list spread sheet is selected and using If/ElseIf it sorts based on what cell they have selected.

Example
If ActiveCell = "ALUMINIZED" Then
ActiveSheet.Range("$A$14:$K$1945").AutoFilter Field:=2
ActiveSheet.Range("$A$14:$K$1945").AutoFilter Field:=4
ActiveSheet.Range("$A$14:$K$1945").AutoFilter Field:=1, Criteria1:= _"Aluminized"

Which is working perfectly. The problem I am having is that some of the cells are two lines so it looks like this
BE
BEARINGS
I don't know how to get it to launch based on that cell content because of the line break in there. Can I make it launch based on the first two characters only?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Assuming the line break is character 10 you could try:

If Activecell = "BE" & Chr(10) & "BEARINGS"
 
Upvote 0
Sorry, I get nothing.
Is there a way to get it an IF to activate based on only a few characters?
 
Upvote 0
Sorry, I get nothing.
Is there a way to get it an IF to activate based on only a few characters?

Try:
If Activecell.Value Like "BE*" then

Did you test the cell contaning BE ... to see if it contains character 10?
 
Upvote 0
I'm not sure how to test for character ten. But the "Like" code is exactly what I need, thank you!
 
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,905
Members
449,478
Latest member
Davenil

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