Splitting text and reading parts of it

aa2000

Board Regular
Joined
Aug 3, 2011
Messages
87
Hi all

So I have two columns in separate workbooks. In the first column there is the short name of the experiment, and in the second one the full name of the experiment. Next to the full name there is a result that I want to put in a cell next to the short name. I need help trying to write the macro to match the two names.
The format is this:

Column1: ShortName

Column2: Experiment ShortName Number

So how can I get the macro to split the text in column2 and look at the part in between the 2 spaces? (ie the short name)

Cheers
 
Anybody have any ideas on how to do this?

I think I would have to split the text in a cell based on a delimiter (in this case a "space") and then only whats between the two spaces. Correct?

Cheers
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Certainly not certain, but maybe:
Before:
Excel Workbook
ABCDE
1Column 1 is as followsHeaderEmptyColumn2 is as follows
2HighTempExperiment Vacuum 6Ok
3LowTempExperiment HighTemp 1Ok
4LowPressureExperiment LowPressure 8Ok
5HighPressureExperiment LowTemp 2Not Ok
6VacuumExperiment HighPressure 1Ok
Sheet1


After:
Excel Workbook
ABCDE
1Column 1 is as followsHeaderEmptyColumn2 is as follows
2HighTempOkExperiment Vacuum 6Ok
3LowTempNot OkExperiment HighTemp 1Ok
4LowPressureOkExperiment LowPressure 8Ok
5HighPressureOkExperiment LowTemp 2Not Ok
6VacuumOkExperiment HighPressure 1Ok
Sheet1


In a Standard Module:
Rich (BB code):
Option Explicit
    
Sub exa()
Dim REX         As Object '<--- RegExp
Dim rngShort    As Range
Dim rngLong     As Range
Dim aryShort    As Variant
Dim aryLong     As Variant
Dim i           As Long
Dim ii          As Long
    
    Set REX = CreateObject("VBScript.RegExp")
    REX.Global = False
    REX.IgnoreCase = False
    
    '// Note: using worksheet's CodeName                                            //
    With Sheet1
        Set rngShort = Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp))
        Set rngLong = Range(.Cells(2, 4), .Cells(.Rows.Count, 4).End(xlUp))
        
        aryShort = rngShort.Value
        aryLong = rngLong.Value
        
        For i = LBound(aryShort, 1) To UBound(aryShort, 1)
            REX.Pattern = "\b" & aryShort(i, 1) & "\b"
            For ii = LBound(aryLong, 1) To UBound(aryLong, 1)
                
                If REX.Test(aryLong(ii, 1)) Then
                    '// Presumes one row header                                     //
                    .Cells(i + 1, 2).Value = .Cells(ii + 1, 5).Value
                    Exit For
                End If
            Next
        Next
    End With
End Sub
 
Upvote 0
Thank you very much, this has got me going in the right direction and I can now adapt it to my project.

Thanks GTO!
 
Upvote 0
I think I would have to split the text in a cell based on a delimiter (in this case a "space") and then only whats between the two spaces
To do this bit would be just like I suggested in your other thread only with a space as the delimiter. So
Code:
Sub ExtractText()
    Dim s As String, a As String
    
    s = "Experiment HighTemp 1"
    a = Split(s, " ")(1)
    MsgBox a
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,522
Messages
6,131,146
Members
449,626
Latest member
Stormythebandit

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