F
ferrogy
First off I am just learning VBA.
The code below is in a module for a workbook. What it does
is send each individual row
of my database to it's own worksheet.(creates one if none
exsist).
The problem is that it replaces the old data that is on
the worksheets with the new data
every time it is run.(ie. I never have more than the
header and ONE row of data)
What I need it to do is add a new row of data every time
the macro is run.
I have tried adding the paste special code that I got from
this page....
http://www.rondebruin.nl/copy1.htm ...but could not get
it to work.
The last row code must only apply to the sheets I am
sending the data to.
Thanks in advance for any help!
Option Explicit
Sub FilterCities()
Dim c As Range
Dim ws As Worksheet
For Each c In Range("STOCKLIST")
If WksExists(c.Value) = False Then
Set ws = Sheets.Add
ws.Name = c.Value
ws.Move After:=Sheets(Sheets.Count)
Sheets(Range("STOCKLIST").Cells(1, 1).Value) _
.Rows("1:1").Copy Destination:=ws.Rows("1:1")
End If
Sheets("CRIT").Range("D2").Value = c.Value
Sheets("DATA").Range("DATABASE").AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=Sheets("CRIT").Range("D12"), _
CopyToRange:=Sheets(c.Value).Range("A1:H1"), _
Unique:=False
Next
MsgBox "Data has been sent"
End Sub
Function WksExists(wksName As String) As Boolean
On Error Resume Next
WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function
The code below is in a module for a workbook. What it does
is send each individual row
of my database to it's own worksheet.(creates one if none
exsist).
The problem is that it replaces the old data that is on
the worksheets with the new data
every time it is run.(ie. I never have more than the
header and ONE row of data)
What I need it to do is add a new row of data every time
the macro is run.
I have tried adding the paste special code that I got from
this page....
http://www.rondebruin.nl/copy1.htm ...but could not get
it to work.
The last row code must only apply to the sheets I am
sending the data to.
Thanks in advance for any help!
Option Explicit
Sub FilterCities()
Dim c As Range
Dim ws As Worksheet
For Each c In Range("STOCKLIST")
If WksExists(c.Value) = False Then
Set ws = Sheets.Add
ws.Name = c.Value
ws.Move After:=Sheets(Sheets.Count)
Sheets(Range("STOCKLIST").Cells(1, 1).Value) _
.Rows("1:1").Copy Destination:=ws.Rows("1:1")
End If
Sheets("CRIT").Range("D2").Value = c.Value
Sheets("DATA").Range("DATABASE").AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=Sheets("CRIT").Range("D12"), _
CopyToRange:=Sheets(c.Value).Range("A1:H1"), _
Unique:=False
Next
MsgBox "Data has been sent"
End Sub
Function WksExists(wksName As String) As Boolean
On Error Resume Next
WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function