Excel vba: extract characters before delimiter in active cell

2Took

Board Regular
Joined
Jun 13, 2022
Messages
203
Office Version
  1. 365
Platform
  1. Windows
Hi,

Not looking for a Function.
  1. Need VBA to extract left characters before delimiter "." in active cell and call it ExL
  2. Need VBA to extract right characters before delimiter " - " in active cell and call it ExR
Got code below, but those are functions, don't need that:

VBA Code:
If InStr(txt, char) > 0 Then Extract_LString = Left(txt, InStr(txt, char) - 2)

If InStr(txt, char) > 0 Then Extract_RString = Right(txt, InStr(txt, char) - 4)
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
How about:
VBA Code:
ExL = Split(ActiveCell, ".")(0) ' Get characters to left of the delimiter '.'
ExR = Split(ActiveCell, " - ")(1) ' Get characters to right of the delimiter ' - '

Change the delimiter to what you want.
 
Upvote 0
Solution
How about:
VBA Code:
ExL = Split(ActiveCell, ".")(0) ' Get characters to left of the delimiter '.'
ExR = Split(ActiveCell, " - ")(1) ' Get characters to right of the delimiter ' - '

Change the delimiter to what you want.
Thank you, but now I am getting below error...
Trying to use ExL & ExR to filter in corresponding column in row 10, where I have filters.
Running your code above on a cell which value looks like this:

H. HeaderName - SearchTerm

2022-11-18_12h28_19.png
 
Upvote 0
ExL is a variable ... Remove the quotes from around it.
The same goes for ExR
 
Upvote 0
Your line of code equates to:
VBA Code:
ActiveSheet.Range("H10").AutoFilter Criteria1:="Search Term"

Filter requires a range of cells, you have 1 cell.
 
Upvote 0
Your line of code equates to:
VBA Code:
ActiveSheet.Range("H10").AutoFilter Criteria1:="Search Term"

Filter requires a range of cells, you have 1 cell.
ok, so what code do I need to fix that?
 
Upvote 0
What range are you trying to filter? H10:H20 for example, or All of column H?
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,457
Members
449,161
Latest member
NHOJ

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