PDA

View Full Version : COPY DATA



oleg_v
03-09-2010, 04:25 AM
HI
I HAVE THIS MACRO:

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

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, "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


I need to change this macro that it not copy rows by month i need it to copy the rows that in column "ae" in cell 4_th and 5_th numbers from the left is "02"

i think that the change should be in the rows:

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



thanks

Bob Phillips
03-09-2010, 04:40 AM
Got an example workbook?

oleg_v
03-09-2010, 05:19 AM
Attached the file

Bob Phillips
03-09-2010, 05:24 AM
Public Sub ProcessData()
Const TEST_COLUMN As String = "Ae" '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim NextRow As Long
NextRow = 6

Dim mnth As Long

With ActiveSheet

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

If .Cells(i, "AE").Offset(0, -4).Value = 0.02 And _
.Cells(i, "AE").Offset(0, -5).Value = 0.02 Then

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

End Sub

oleg_v
03-09-2010, 05:48 AM
hi
It copyes me only one line
why?

in the code why you use 0.02 and -4 and -5

Bob Phillips
03-09-2010, 06:04 AM
Because you said you wanted to test 4 and 5 cells lef (-4 and -5) for 02. I could only see 0.02 so tred that.

oleg_v
03-09-2010, 06:22 AM
i am sorry for my English but i meant 4_th and 5_th location in the cell in column 'ae" i need to test only 4_th and 5_th locations in the cell in column "AE"
and to copy the row

Bob Phillips
03-09-2010, 08:34 AM
I don't understand what you mean. What cells are the ... 4_th and 5_th locations in the cell in column "AE"?

oleg_v
03-09-2010, 10:23 AM
hi

i meant each cell in column "ae" contains numbers ans letters
what i meant is 4_th and 5_th character or number whithin the cell

for example first 3 charachters in cells are "1cv" and i need to adress to 4_th anf 5_th


thanks

Bob Phillips
03-09-2010, 11:37 AM
OK, is this better?



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

Dim mnth As Long

With ActiveSheet

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

If Mid$(.Cells(i, "AE").Value2, 5, 2) = "02" Then

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

End Sub