Macro To Concatenate

zaska

Well-known Member
Joined
Oct 24, 2010
Messages
1,046
Hi all,

I have the following data...

INSTRUMENT SYMBOL EXPIRY DATE

FUTIDX BBBB MAY
FUTIDX BBBB JUN
FUTIDX BBBB JULY
FUTIDX CCCC MAY
FUTIDX CCCC JUN
FUTIDX DDDD JULY
OPSTK BBBB MAY
OPSTK BBBB JUN


I want to convert this data as follows

BBBB-I
BBBB-II
BBBB-III
CCCC-I
CCCC-II
DDDD-III

and DELETE all the symbols starting with the Instrument name " OPSTK".

Thank you
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I would do a Formula next to it. Can you make a small table with May=I, June=II, etc.

Then do a

=MID(A1,8,4) & "-" & vlookup(TRIM(MID(A1,13,10),your table,2,0)

Bascially get the BBBB or CCCC, etc out of the cell, put a "-", then lookup the I/II/III.

I would also put a if(left(a1,5)="OPSTK","") in front of the above formula to blank it out if it's OPSTK
 
Upvote 0
Thank you..

Last thing that i would like to delete all the rows from where the OPSTK Instrument starts.

The data is arranged in a sequence that FUTSK symbols are arranged first and then OPSTK symbols later...i don't want OPSTK Symbols data...i want to complete delte the range of OPSTK symbols..

IS it possible?

Thank you once again
 
Upvote 0
For VBA:
Code:
Public Sub Phoo()
    Dim vararr As Variant
    Dim lngItem As Long, lngRN As Long
    
    With Range("A2:A9")
        vararr = Filter(Evaluate("transpose(if(row()," & .Address & "&""-""&" & .Offset(, 1).Address & "))"), "OPSTK", False)
    End With
    
    lngRN = 1
    For lngItem = LBound(vararr) To UBound(vararr)
        If lngItem > LBound(vararr) Then
            If Split(vararr(lngItem), "-")(1) = Split(vararr(lngItem - 1), "-")(0) Then
                lngRN = lngRN + 1
            Else
                lngRN = 1
            End If
        End If
        vararr(lngItem) = Split(vararr(lngItem), "-")(1) & "-" & Application.Roman(lngRN)
    Next lngItem
    
    Range("E2").Resize(UBound(vararr) + 1).Value = Application.Transpose(vararr)
End Sub

Currently does not qualify the sheet, so sheet must be active when you run this code.

Change ranges to suit. Currently assumes your table in A2:A9, and assumes results to be written out to column E.
 
Upvote 0
I'll take a stab at it....<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Assuming FUTIDX starts at A2<o:p></o:p>
<o:p></o:p>
IF((A2="OPSTK"),"",concatenate(B2&”-“&(Vlookup(C2,Your Table,2,false))))
<o:p></o:p>
My excel is currently locked up so I couldn’t test this out.
<o:p></o:p>
Hopefully it works or at least helps you find the solution.<o:p></o:p>
 
Upvote 0
Formula approach:

Excel Workbook
ABCDEFG
1INSTRUMENTSYMBOLEXPIRYCODEROMANRESULT
2FUTIDXBBBBMAYBBBBIBBBB-I
3FUTIDXBBBBJUNBBBBIIBBBB-II
4FUTIDXBBBBJULYBBBBIIIBBBB-III
5FUTIDXCCCCMAYCCCCICCCC-I
6FUTIDXCCCCJUNCCCCIICCCC-II
7FUTIDXDDDDJULYDDDDIDDDD-I
8OPSTKBBBBMAY#NUM!I#NUM!
9OPSTKBBBBJUN#NUM!II#NUM!
Sheet1


I am showing a stepped approach, using two helper columns, but you could wrap it up into a single result column if you wish.
 
Upvote 0
I just twigged that the roman numerals are month values, so:
Excel Workbook
ABCDEFG
1INSTRUMENTSYMBOLEXPIRYCODEROMANRESULT
2FUTIDXBBBBMAYBBBBIBBBB-I
3FUTIDXBBBBJUNBBBBIIBBBB-II
4FUTIDXBBBBJULYBBBBIIIBBBB-III
5FUTIDXCCCCMAYCCCCICCCC-I
6FUTIDXCCCCJUNCCCCIICCCC-II
7FUTIDXDDDDJULYDDDDIIIDDDD-III
8OPSTKBBBBMAY#NUM!I#NUM!
9OPSTKBBBBJUN#NUM!II#NUM!
Sheet1
Excel 2010
Cell Formulas
RangeFormula
F2=ROMAN(MONTH("1-"&C2)-4)
G2=E2&"-"&F2
#VALUE!
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
 
Upvote 0
Thank you for the Help.

I have one query ...I tried few times to post excel sheets but i was not successful ..

I tried with Xl jeanie...but i can't figure it out where i went wrong.
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,786
Members
452,942
Latest member
VijayNewtoExcel

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