VBA search for characters+hard return

Dabenic

New Member
Joined
Apr 28, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello all!

I have a series of cells I need to work on and separate the contents based on criteria. The common characteristic marking the point where I need to separate text is two commas followed by a hard return.

How can I format the search criteria so it looks for ",," plus the hard return (vbLf)?


Thank you!
 
In your example, is there a hard return after sample4 and the 3 commas?
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Without resorting to VBA, this might do it:

Book2
A
2sample1,sample2,,sample4,,, sample7,,sample8,, extract1,extract2,extract4,,,,,,extract10,, data1,data3,data4
3
4sample1,sample2,,sample4,,, sample7,,sample8,,
5 extract1,extract2,extract4,,,,,,extract10,,
6data1,data3,data4
Sheet3
Cell Formulas
RangeFormula
A4A4=LEFT(A2,3+FIND(",,"&CHAR(10),SUBSTITUTE(A2,",,,","~")))
A5A5=MID(A2,1+LEN(A4),1+FIND(",,"&CHAR(10),SUBSTITUTE(RIGHT(A2,LEN(A2)-LEN(A4)),",,,","~",LEN(A2)+1)))
A6A6=RIGHT(A2,LEN(A2)-(LEN(A4)+LEN(A5)+1))
 
Upvote 0
Welcome to Mr. Excel.

It might help if you had examples of your data and expected results.

Do you mean this:

Code:
=LEFT(A2,FIND(",,"&CHAR(10),A2)-1)

and

Code:
=RIGHT(A2,LEN(A2)-FIND(",,"&CHAR(10),A2)-1)

with your text in A2 ??
These might work. I will spend some more time working with them.
 
Upvote 0
Thank you kweaver and Micron for your help! I was able to take both of your inputs into consideration. I had found a Split function but couldn't get it to work until now. Below is what I have that works.


VBA Code:
Sub CommaCommaHR_Split()
  
Dim sample As String
Dim EX As Integer
Dim extract() As String
  
  sample = Range("B6")
  extract = Split(sample, ",," & Chr(13))

  For EX = 0 To UBound(extract)
  
        Cells(EX + 6, 2).Value = extract(EX)
  
  Next EX
    

End Sub
 
Upvote 0
With only ONE example, it's difficult (impossible) to write code that will work in all of your cases. Please provide add'l examples.
 
Upvote 0

Forum statistics

Threads
1,215,456
Messages
6,124,939
Members
449,197
Latest member
k_bs

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