Extract and Delete Characters Based on Condition

madhuchelliah

Board Regular
Joined
Nov 22, 2017
Messages
226
Office Version
  1. 2019
Platform
  1. Windows
Hello all, i want to extract data in a selected range of cells based on condition. If the 9th character is an alphabet, then the rest of the characters(from 10th) in the cell to be copied to the adjacent cell. If it is not an alphabet then from 9th character in the cell to be copied to the adjacent cell. In both cases after copying, the copied data should be deleted from the selected range. Please see the example for better clarity. Example is just for reference. Thank you.

Book1
IJKLM
14InputOutput
1512345678A002X12345678A002X
161234567891012345678910
Sheet1
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
How about
+Fluff 1.xlsm
IJKLM
14InputOutput
1512345678A002X12345678A002X
161234567891012345678910
Main
Cell Formulas
RangeFormula
L15:L16L15=LEFT(I15,8+ISERROR(MID(I15,9,1)+0))
M15:M16M15=MID(I15,9+ISERROR(MID(I15,9,1)+0),100)
 
Upvote 0
How about
+Fluff 1.xlsm
IJKLM
14InputOutput
1512345678A002X12345678A002X
161234567891012345678910
Main
Cell Formulas
RangeFormula
L15:L16L15=LEFT(I15,8+ISERROR(MID(I15,9,1)+0))
M15:M16M15=MID(I15,9+ISERROR(MID(I15,9,1)+0),100)
Hello Fluff, my apologies not to mention the requirement as VBA solution. BTW the formula works great. Thank you.
 
Upvote 0
What column is the data in & what is the first row?
 
Upvote 0
Ok, how about
VBA Code:
Sub madhuchelliah()
   With Selection
      .Offset(, 1).Value = Evaluate(Replace("if({1},mid(@,9+iserror(mid(@,9,1)+0),100))", "@", .Address))
      .Value = Evaluate(Replace("if({1},left(@,8+iserror(mid(@,9,1)+0)))", "@", .Address))
   End With
End Sub
 
Upvote 0
Solution
Ok, how about
VBA Code:
Sub madhuchelliah()
   With Selection
      .Offset(, 1).Value = Evaluate(Replace("if({1},mid(@,9+iserror(mid(@,9,1)+0),100))", "@", .Address))
      .Value = Evaluate(Replace("if({1},left(@,8+iserror(mid(@,9,1)+0)))", "@", .Address))
   End With
End Sub
Hello Fluff, it is working as expected. Thanks for your time.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,539
Members
449,316
Latest member
sravya

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