Vba

ana1991

New Member
Joined
Sep 29, 2015
Messages
26
Good morning

I have a question regarding VBA and bloomberg. I want to automatically get a table from bloomberg, with various countries, dates, events...
Then I want to filter the main table (the one I get from bloomberg) by country, copying the filtered table into a new sheet for each country and sort each new table by date.
Is there a way to do it?


Thanks in advance!

Here is an example of the bloomberg table:


TickersCountryEventDatePeriodMedianAverageActual Prior
ABrazilXXX01-06-2015SEP0,680,300,220,09
BPortugalXXX02-06-2015SEP0,970,770,060,83
CEuro ZoneXX103-06-2015SEP0,320,640,680,23
DSpainXX204-06-2015AUG0,820,230,670,15
ETurkeyXXX05-06-2015SEP0,790,250,070,43
FFranceXX506-06-2015SEP0,720,440,130,84
GGermanyXX707-06-2015AUG0,440,380,040,23
HRomaniaXX108-06-2015AUG0,240,210,750,10
IGermanyXX309-06-2015SEP0,880,030,890,31
JPortugalXX810-06-2015JUL0,440,800,970,37
KEuro ZoneXX611-06-2015SEP0,870,720,140,27
LSpainXXX12-06-2015SEP0,520,030,800,90
MBrazilXX013-06-2015AUG0,340,390,460,27
NGermanyXX814-06-2015SEP0,230,900,040,73
OEuro ZoneXX215-06-2015SEP0,240,010,160,19
PUKXXX16-06-2015SEP0,070,020,910,77

<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Start with this to create your sheets:
Code:
Sub CAddSheets()
Dim count() As Variant

Set Rng1 = Range("B2:B10000")
     
   For Each Cell In Rng1
   If Cell.Value = "" Then GoTo First
   
   ReDim Preserve count(0 To x) As Variant
   
   For i = 0 To x - 1
   If Cell.Value = count(i) Then
   GoTo First
   End If
   Next i
     
   count(x) = Cell.Value
   x = x + 1

First:
   Next
   
For i = 0 To UBound(count) - 1

Worksheets.Add(, Worksheets(Worksheets.count)).Name = count(i)
Next

   
End Sub
 
Upvote 0
Copy this code in a module, paste your source data on Sheet1 and run the macro
Code:
Sub CAddSheets()
Dim Count() As Variant
Dim Ws As Worksheet
Dim WsDest As Worksheet

Application.ScreenUpdating = False


Set Ws = Worksheets("Sheet1")

Set Rng1 = Range("B2:B10000")
     
   For Each Cell In Rng1
   If Cell.Value = "" Then GoTo First
   
   ReDim Preserve Count(0 To x) As Variant
   
   For i = 0 To x - 1
   If Cell.Value = Count(i) Then
   GoTo First
   End If
   Next i
     
   Count(x) = Cell.Value
   x = x + 1

First:
   Next
   
For i = 0 To UBound(Count) - 1
If ChWs(Count(i)) = True Then
Worksheets.Add(, Worksheets(Worksheets.Count)).Name = Count(i)
End If
Next
Ws.Select

For i = 0 To UBound(Count) - 1
Set WsDest = Worksheets(Count(i))
Ws.Range("A1:I1").Select
Selection.Copy
WsDest.Range("A1").PasteSpecial xlPasteAll
Next

Ws.Select

For i = 0 To UBound(Count) - 1
Ws.Cells(1, 2).Select
Selection.AutoFilter Field:=2, Criteria1:=Count(i)

Ws.Range("A2").Select
Ws.Range(Selection, Selection.End(xlDown)).Select
Ws.Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy

Set WsDest = Worksheets(Count(i))
WsDest.Range("A2").PasteSpecial xlPasteAll
WsDest.Range("D2:D10000").Sort WsDest.Range("D2"), xlAscending
Next
Ws.Cells(1, 2).Select
Selection.AutoFilter Field:=2

Application.ScreenUpdating = True
End Sub

Function ChWs(ShName As Variant)
For Each Worksheet In ThisWorkbook.Worksheets
If Worksheet.Name = ShName Then
ChWs = False
Exit Function
End If
Next
ChWs = True
End Function
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,944
Members
449,198
Latest member
MhammadishaqKhan

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