Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default How to copy data as per date into new worksheet?

Hi to all
My Filed is like...
Date,Group,PartyName,Amount
1-july, Payment,abc,2345
1-july,Payment,xyz,6790
1-july,Recipt,pqr,8900
2-july,recipt,jjj,9000
2-july,payment,mmm,8907

I have data which i want to copy, Every day as per Date into new worksheet
with date name of worksheet. In New Worksheet it should be copy as per Group
filed, in group filed i have Payment & Recipt only.

It should copy like

Date:- 1-July
a1, b1, c1, d1, e1, f1
Payment, PartyName,Amount Recipt,Partyname,Amoumt.
Payment,abc,2345 Recipt,pqr,8900
Payment,xyz,6790

and if any new enrty done on old date it should copy into that date sheet
only.
Any help
Thanks

Tiya


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default How to copy data as per date into new worksheet?

put this in a standard module

Option Explicit

Sub PopulateData()
' assume input file has a worksheet called Data
Dim ws As Worksheet
Set ws = Worksheets("data")
Dim rw As Long ' index for reading data
Dim targetrow As Long ' row for writing data
Dim wsTarget As Worksheet ' where data is to go
Dim Col As Long ' used for setting pmt or rct column

rw = 2 'assumes first row is heading

Do Until ws.Cells(rw, 1).Value = ""
If InStr(UCase(Cells(rw, 2).Value), "REC") 0 Then
Col = 4
Else
Col = 1
End If
Set wsTarget = safeSheet(Format$(ws.Cells(rw, 1).Value, "dd-mmmm"))
targetrow = wsTarget.Cells(56000, Col).End(xlUp).Row + 1

With wsTarget
With .Range(.Cells(targetrow, Col), .Cells(targetrow, Col + 2))
.Value = ws.Range(ws.Cells(rw, 2), ws.Cells(rw, 4)).Value
End With
End With
rw = rw + 1
Loop


End Sub
Private Function safeSheet(sSheetName As String) As Worksheet
On Error Resume Next
Set safeSheet = Worksheets(sSheetName)
If Err.Number < 0 Then
Err.Clear
Set safeSheet = ThisWorkbook.Worksheets.Add
safeSheet.Name = sSheetName
If Err.Number < 0 Then GoTo trap
End If
On Error GoTo 0
Exit Function
trap:
MsgBox Err.Description, , "Error Adding Worksheet:" & sSheetName
On Error GoTo 0
End Function


"Tiya" wrote:

Hi to all
My Filed is like...
Date,Group,PartyName,Amount
1-july, Payment,abc,2345
1-july,Payment,xyz,6790
1-july,Recipt,pqr,8900
2-july,recipt,jjj,9000
2-july,payment,mmm,8907

I have data which i want to copy, Every day as per Date into new worksheet
with date name of worksheet. In New Worksheet it should be copy as per Group
filed, in group filed i have Payment & Recipt only.

It should copy like

Date:- 1-July
a1, b1, c1, d1, e1, f1
Payment, PartyName,Amount Recipt,Partyname,Amoumt.
Payment,abc,2345 Recipt,pqr,8900
Payment,xyz,6790

and if any new enrty done on old date it should copy into that date sheet
only.
Any help
Thanks

Tiya


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default How to copy data as per date into new worksheet?

Brilliant solution.
Can we also be able to "split" the data into 2 within a date sheet regarding
it beeing a "receipt" or "payment"?
Ragards
J_J

"Patrick Molloy" wrote in message
...
put this in a standard module



Option Explicit

Sub PopulateData()
' assume input file has a worksheet called Data
Dim ws As Worksheet
Set ws = Worksheets("data")
Dim rw As Long ' index for reading data
Dim targetrow As Long ' row for writing data
Dim wsTarget As Worksheet ' where data is to go
Dim Col As Long ' used for setting pmt or rct column

rw = 2 'assumes first row is heading

Do Until ws.Cells(rw, 1).Value = ""
If InStr(UCase(Cells(rw, 2).Value), "REC") 0 Then
Col = 4
Else
Col = 1
End If
Set wsTarget = safeSheet(Format$(ws.Cells(rw, 1).Value, "dd-mmmm"))
targetrow = wsTarget.Cells(56000, Col).End(xlUp).Row + 1

With wsTarget
With .Range(.Cells(targetrow, Col), .Cells(targetrow, Col + 2))
.Value = ws.Range(ws.Cells(rw, 2), ws.Cells(rw, 4)).Value
End With
End With
rw = rw + 1
Loop


End Sub
Private Function safeSheet(sSheetName As String) As Worksheet
On Error Resume Next
Set safeSheet = Worksheets(sSheetName)
If Err.Number < 0 Then
Err.Clear
Set safeSheet = ThisWorkbook.Worksheets.Add
safeSheet.Name = sSheetName
If Err.Number < 0 Then GoTo trap
End If
On Error GoTo 0
Exit Function
trap:
MsgBox Err.Description, , "Error Adding Worksheet:" & sSheetName
On Error GoTo 0
End Function


"Tiya" wrote:

Hi to all
My Filed is like...
Date,Group,PartyName,Amount
1-july, Payment,abc,2345
1-july,Payment,xyz,6790
1-july,Recipt,pqr,8900
2-july,recipt,jjj,9000
2-july,payment,mmm,8907

I have data which i want to copy, Every day as per Date into new
worksheet
with date name of worksheet. In New Worksheet it should be copy as per
Group
filed, in group filed i have Payment & Recipt only.

It should copy like

Date:- 1-July
a1, b1, c1, d1, e1, f1
Payment, PartyName,Amount Recipt,Partyname,Amoumt.
Payment,abc,2345 Recipt,pqr,8900
Payment,xyz,6790

and if any new enrty done on old date it should copy into that date sheet
only.
Any help
Thanks

Tiya




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find matching date in another worksheet, copy and paste data Shoney Excel Discussion (Misc queries) 1 November 8th 07 11:45 PM
copy date from worksheet to another worksheet (same File0 wamajkr Excel Discussion (Misc queries) 1 January 15th 07 03:32 PM
How do I copy a date in a worksheet cell to another worksheet? JennLee Excel Worksheet Functions 3 February 17th 06 05:38 PM
Copy data in new worksheet as per date Tiya Excel Programming 0 August 1st 05 08:01 AM
Copy Data as per date into new worksheet. Tiya Excel Programming 0 July 30th 05 11:34 AM


All times are GMT +1. The time now is 06:28 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"