View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Create worksheets for each matching values in Column?

Hi Adrian,

Here is a shot


Sub MyCurrencies()
Dim cNumRows As Long
Dim i As Long
Dim cNextRow As Long
Dim sh As Worksheet

With ActiveSheet
cNumRows = .Cells(Rows.Count, "C").End(xlUp).Row
For i = 1 To cNumRows
If Not SheetExists(.Cells(i, "C").Value) Then
Worksheets.Add.Name = .Cells(i, "C").Value
Worksheets(.Cells(i, "C").Value).Cells(1, "A").Value =
..Cells(i, "C").Value
Else
Set sh = Worksheets(.Cells(i, "C").Value)
cNextRow = sh.Cells(Rows.Count, "A").End(xlUp).Row + 1
sh.Cells(cNextRow, "A").Value = .Cells(i, "C").Value
End If
Next i
End With

End Sub

'-----------------------------------------------------------------
Function SheetExists(sh As String, _
Optional wb As Workbook) As Boolean
'-----------------------------------------------------------------
Dim oWs As Worksheet
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = CBool(Not wb.Worksheets(sh) Is Nothing)
On Error GoTo 0
End Function



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Kobayashi " wrote in message
...
I have one worksheet with multiple columns. In one of these columns (C)
I have a number of currencies. However, both the number of rows and
number of currencies can change from day to day. I would like to be
able to create additional worksheets for each of the relevant
currencies and cut the data from workseet 1 into each of the individual
currency sheets?

For example:

Column B has 4 rows.

Row 1 has value of USD
Row 2 has value of EUR
Row 3 has value of EUR
Row 4 has value of FRF
etc.....

After running the procedure I should now have three workseets, one for
USD with one row, one for EUR with two rows and one for FRF with one
row.

Any pointers in the right direction would be appreciated.

Regards,

Adrian


---
Message posted from http://www.ExcelForum.com/