Copy only date row into one excel sheet to another

Hello,

I have an excel macro-enabled excel file DayBook.xlsm with multiple headers. One header for one date.

Date      Particulars      Bill No.      Quantity      Cash Sale      Credit Sale      Cash Expenses      Expenses Through Cheque
1-Jan-14      Sales      447      2000                        
1-Jan-14      Sales      447      2000            185500.00            
1-Jan-14      Salaries                              68000.00      
1-Jan-14      Salaries                              15000.00      
                                          
Date      Particulars      Bill No.      Quantity      Cash Sale      Credit Sale      Cash Expenses      Expenses Through Cheque
2-Jan-14      Purchases                                    254850.00
                                          
Date      Particulars      Bill No.      Quantity      Cash Sale      Credit Sale      Cash Expenses      Expenses Through Cheque
3-Jan-14      Sales            300      88600.00                  


I wish to create a macro button so that when I click the button, it will copy only the date rows into another workbook contains only header as shown below. So that I will get only one header and no empty rows in between the date rows.

Date      Particulars      Bill No.      Quantity      Cash Sale      Credit Sale      Cash Expenses      Expenses Through Cheque

I have added mySales macro but it is not running
DayBook.xlsm
Swen LeeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Place the following code on a standard module of the source workbook. Create a button on the sheet and assign the macro to it.

The code will create another workbook with the desired data and save the workbook at the location of the source workbook.
Sub CopyDateRows()
Dim swb As Workbook, dwb As Workbook
Dim sws As Worksheet, dws As Worksheet
Dim slr As Long
Dim srng As Range, cell As Range
Dim sPath As String, fName As String

Application.ScreenUpdating = False
Set swb = ThisWorkbook
Set sws = swb.Sheets(1)
lr = sws.Cells(Rows.Count, "A").End(xlUp).Row
Set srng = sws.Range("A2:A" & lr)
sPath = swb.Path
fName = Left(swb.Name, InStr(swb.Name, ".") - 1) & Format(Now, "mmddyy hhmmss") & ".xlsx"
Workbooks.Add
Set dwb = ActiveWorkbook
Set dws = ActiveSheet

sws.Range("A1:H1").Copy
dws.Range("A1").PasteSpecial xlPasteValues

For Each cell In srng
    If IsDate(cell) Then
        sws.Range(sws.Cells(cell.Row, "A"), sws.Cells(cell.Row, "H")).Copy dws.Range("A" & Rows.Count).End(3)(2)
    End If
Next cell
dws.UsedRange.Columns.AutoFit
dwb.SaveAs sPath & "\" & fName
dwb.Close
Application.ScreenUpdating = True
MsgBox "Workbook created successfully.", vbInformation, "Done!"
End Sub

Open in new window

For detail refer to the attached workbook.
DayBook.xlsm
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Swen LeeAuthor Commented:
Amazing! Thank you for spending time to help a novice.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Swen Lee! Glad I could help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.