crashing1912
New Member
- Joined
- Sep 8, 2011
- Messages
- 19
Hi all,
I have a master sheet of billing information with 1,000 lines of data for 30 different clients and I have 30 sheets with the names of each client as the sheet name. I need a macro, which will copy and paste each client's information from the master sheet into the client's worksheet five lines below the last entry. In addition, I need the macro to add a new sheet if the client name is not one of the client sheets. Below, I put what code I have, but over the past week of trying to figure this out, I can't really say how useful it is any more. I greatly appreciate any help on this. Let me know if you need anymore information. Thanks!
Sub Copyandpaste ()
Dim wsAll As Worksheet
Dim wsCrit As Worksheet
Dim wsNew As Worksheet
Dim LastRow2 As Long
Dim LastRowCrit As Long
Dim I As Long
Dim FindLastRow As Long
Dim sh As Worksheet
Set wsAll = Worksheets("All") ' change All to the name of the worksheet the existing data is on
LastRow2 = wsAll.Range("A" & Rows.count).End(xlUp).Row
FindLastRow = Range("A65536").End(xlUp).Row
Set wsCrit = Worksheets.Add
' column A has the criteria
wsAll.Range("B1:B" & LastRow2).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wsCrit.Range("A1"), Unique:=True
LastRowCrit = wsCrit.Range("A" & Rows.count).End(xlUp).Row
For Each sh In ActiveWorkbook.Worksheets
If wsCrit.Range("A2") <> sh.Name Then
wsAll.Rows("1:" & LastRow2).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=wsCrit.Range("A1:A2"), _
CopyToRange:=ws.Range("A1"), Unique:=False
wsCrit.Rows(2).Delete
Next sh
Else
For I = 2 To LastRowCrit
Set wsNew = Worksheets.Add
wsNew.Name = wsCrit.Range("A2")
wsAll.Rows("1:" & LastRow2).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=wsCrit.Range("A1:A2"), _
CopyToRange:=wsNew.Range("A1"), Unique:=False
wsCrit.Rows(2).Delete
Next I
Application.DisplayAlerts = False
wsCrit.Delete
Application.DisplayAlerts = True
End If
End Sub
I have a master sheet of billing information with 1,000 lines of data for 30 different clients and I have 30 sheets with the names of each client as the sheet name. I need a macro, which will copy and paste each client's information from the master sheet into the client's worksheet five lines below the last entry. In addition, I need the macro to add a new sheet if the client name is not one of the client sheets. Below, I put what code I have, but over the past week of trying to figure this out, I can't really say how useful it is any more. I greatly appreciate any help on this. Let me know if you need anymore information. Thanks!
Sub Copyandpaste ()
Dim wsAll As Worksheet
Dim wsCrit As Worksheet
Dim wsNew As Worksheet
Dim LastRow2 As Long
Dim LastRowCrit As Long
Dim I As Long
Dim FindLastRow As Long
Dim sh As Worksheet
Set wsAll = Worksheets("All") ' change All to the name of the worksheet the existing data is on
LastRow2 = wsAll.Range("A" & Rows.count).End(xlUp).Row
FindLastRow = Range("A65536").End(xlUp).Row
Set wsCrit = Worksheets.Add
' column A has the criteria
wsAll.Range("B1:B" & LastRow2).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wsCrit.Range("A1"), Unique:=True
LastRowCrit = wsCrit.Range("A" & Rows.count).End(xlUp).Row
For Each sh In ActiveWorkbook.Worksheets
If wsCrit.Range("A2") <> sh.Name Then
wsAll.Rows("1:" & LastRow2).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=wsCrit.Range("A1:A2"), _
CopyToRange:=ws.Range("A1"), Unique:=False
wsCrit.Rows(2).Delete
Next sh
Else
For I = 2 To LastRowCrit
Set wsNew = Worksheets.Add
wsNew.Name = wsCrit.Range("A2")
wsAll.Rows("1:" & LastRow2).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=wsCrit.Range("A1:A2"), _
CopyToRange:=wsNew.Range("A1"), Unique:=False
wsCrit.Rows(2).Delete
Next I
Application.DisplayAlerts = False
wsCrit.Delete
Application.DisplayAlerts = True
End If
End Sub