PDA

View Full Version : excel copy



oleg_v
12-20-2009, 11:15 PM
hi
I have an excel table:
1549.719 30/12/2008
1549.736 06/01/2009
1549.758 06/01/2009
1549.953 12/01/2009
1549.969 12/01/2009
1549.803 14/01/2009
1550.015 26/01/2009
1550 04/05/2009
1549.962 04/05/2009
1549.87 04/05/2009
1549.923 28/06/2009
1549.914 28/06/2009
1549.97 28/06/2009
1549.997 06/08/2009
1549.965 10/08/2009
1549.907 14/10/2009
1549.9226 14/10/2009
1549.9159 15/10/2009
1549.87 23/10/2009
1549.923 23/10/2009
1550.1816 01/11/2009
1550.0964 01/11/2009
1550.005 04/11/2009
1550.039 04/11/2009
1549.973 08/11/2009
1549.963 08/11/2009
1550.049 08/11/2009

i need a macro to copy only the data thatn belongs to each month and copy that data to ather sheet
the month i need to choose through the question

Bob Phillips
12-21-2009, 01:33 AM
Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim NextRow As Long
Dim mnth As Long

With ActiveSheet

mnth = InputBox("Supply the required month number")
If mnth > 0 And mnth <= 12 Then

LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To LastRow

If Month(.Cells(i, "B").Value) = mnth Then

NextRow = NextRow + 1
.Rows(i).Copy Worksheets("Sheet2").Cells(NextRow, "A")
End If
Next i
End If
End With

End Sub

oleg_v
12-21-2009, 03:27 AM
I can not get it to work

Bob Phillips
12-21-2009, 04:24 AM
Why, what have you done?

geekgirlau
12-21-2009, 11:22 PM
Please post a sample with the code you have added so far

Aussiebear
12-24-2009, 01:07 AM
oleg_v are you wanting each months data to go to its own sheet? Currently when you select a particular month it will overwrite the previous month transferred.

oleg_v
12-24-2009, 01:14 AM
Hi
i want it to overwrite
i need that macro to choose not the hole row i need it to choose the data between the columns "c-g" and reference column with all the dates k

thanks

Aussiebear
12-24-2009, 02:39 AM
This is significantly different to that which you initially requested. You supplied what looked like two columns of data......

Okay here's what you need to do. Attach a workbook by clicking on "Go Advanced", scroll down until you see "Manage attachments", and upload a sample workbook.

In post #3 you wrote "I can not get it to work". We'd need to be one of these.........:wizard: to even come close.

oleg_v
12-24-2009, 03:23 AM
In the column "AE" you will see the dates

every time i choose a different month the data that should be copyed
is between the columns "E-AD"

Bob Phillips
12-24-2009, 03:46 AM
Just change this



If Month(.Cells(i, "B").Value) = mnth Then

NextRow = NextRow + 1
.Rows(i).Copy Worksheets("Sheet2").Cells(NextRow, "A")
End If


to



If Month(.Cells(i, "AE").Value) = mnth Then

NextRow = NextRow + 1
.Cells(i, "E").Resize(, 26).Copy Worksheets("Sheet2").Cells(NextRow, "A")
End If

oleg_v
12-24-2009, 04:20 AM
hi
it works
can i paste the data to the sheet2 that will start in "D6"

Aussiebear
12-24-2009, 06:16 PM
oleg_v, Can you get your requests more organised please? That is 4 posts now where you continually change what you are chasing.

Bob Phillips
12-25-2009, 05:41 PM
Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim NextRow As Long
Dim mnth As Long

With ActiveSheet

mnth = InputBox("Supply the required month number")
If mnth > 0 And mnth <= 12 Then

LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
NextRow = 5
For i = 1 To LastRow

If Month(.Cells(i, "AE").Value) = mnth Then

NextRow = NextRow + 1
.Cells(i, "E").Resize(, 26).Copy Worksheets("Sheet2").Cells(NextRow, "D")
End If
Next i
End If
End With

End Sub

oleg_v
02-14-2010, 11:05 PM
HI
I changed a few locations im the macro and it does not work??

Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim NextRow As Long
Dim mnth As Long

With ActiveSheet

mnth = InputBox("Supply the required month number")
If mnth > 0 And mnth <= 12 Then

LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
NextRow = 5
For i = 1 To LastRow

If Month(.Cells(i, "AU").Value) = mnth Then

NextRow = NextRow + 1
.Cells(i, "E").Resize(, 2).Copy Worksheets("Sheet2").Cells(NextRow, "D")
End If
Next i
End If
End With

End Sub

it writes me "type mismach" at thus line " If Month(.Cells(i, "AU").Value) = mnth Then"

thanks

Aussiebear
02-14-2010, 11:47 PM
Please edit your post and wrap your code with the VBA tags. You've been here long enough to know what is required by now. Its not as if this is the first time you.ve been asked to do this either

Aussiebear
02-14-2010, 11:50 PM
Look at the line you are quoting..... Is there a spelling mistake there?

If Month(.Cells(i, "AU").Value) = mnth Then

Fix the mistake and run it again.

oleg_v
02-14-2010, 11:58 PM
Hi
i can not find any mistakes
what else can i do??

Bob Phillips
02-15-2010, 01:17 AM
It looks at those some of the cells in column AU contain text. Is that so?

oleg_v
02-15-2010, 01:33 AM
seems to me i found the problem
the first 3 cels in the column were empty