LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 38
Default Copy data based on month?

Thanks very much it works.
--
Sophie


"Gary''s Student" wrote:

Enter the following event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Set a1 = Range("A1")
If Intersect(Target, a1) Is Nothing Then Exit Sub
Application.EnableEvents = False
Dim s1 As Worksheet, s2 As Worksheet
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
s2.Cells.Clear
k = 1
n = Cells(Rows.Count, "A").End(xlUp).Row
v = a1.Value
For i = 1 To n
If Month(Cells(i, 1).Value) = v Then
Cells(i, 1).EntireRow.Copy s2.Cells(k, 1)
k = k + 1
End If
Next
Application.EnableEvents = True
End Sub

After the installation, type a month (as a number) in A1 (4 for March) and
the March data will be copied to Sheet2.

Type a new value, and the data on Sheet2 will be refreshed.


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm
--
Gary''s Student - gsnu200843


"Sophie" wrote:

I have a spreadsheet(sheet1) that data is inserted throughout the year. I
need a formula or vb code so that by entering a month in cell A1, it will
copy all entries in that month and paste it onto another sheet(sheet2).

Data col= A to E (Col A= date)

Thank you

--
Sophie

 
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
Month based data addition to worksheet Brian Excel Worksheet Functions 1 April 28th 08 05:21 PM
Pull data based on month MikeJ Excel Discussion (Misc queries) 5 January 4th 08 04:50 PM
Pull in a colum of financial data based on the month Bradon Excel Worksheet Functions 1 September 15th 06 07:37 AM
Get Data based on Month and Year karstens Excel Worksheet Functions 1 August 2nd 06 12:42 AM
Referencing data in different worksheet based on month name cosmo_canuck Excel Worksheet Functions 3 August 22nd 05 07:27 AM


All times are GMT +1. The time now is 12:42 PM.

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

About Us

"It's about Microsoft Excel"