PDA

View Full Version : Excel Macro



d_raghu9
03-22-2006, 07:44 PM
Hi there,

I am very much new to VBA as well as the forum.

I need some help in copy and past of VBA cells

My problem is

I need to select 3 cells of a row (which has 10 cells) copy them and paste them in new worksheet which is already created.

The cells of the row should be selected only if the value in "B" is equal to 'Good'

This checking should start from first row and end till the last row.

So In programming terms

start at first row
if(B1)=='Good'
copy A1, D1, G1 of the perticular row
go to another worksheet (Worksheet 2)
find the last unused row
Paste the copied vaues
Go back to the previous worksheet (Worksheet 1)
increment B1 to B2 (next row)
Repeat the same steps again.
This should happen till the end of row in worksheet 1


Sorry if i am sounding confusing.

Any help would be greately appreciated.

Thank you
Raghu

Jacob Hilderbrand
03-22-2006, 08:36 PM
Ok, so assuming we are copying from Sheet1 to Sheet2 then.


Dim i As Long
Dim Row As Long
Dim LastRow As Long

LastRow = Sheets("Sheet1").Range("A65536").End(xlUp).Row
Row = Sheets("Sheet2").Range("A65536").End(xlUp).Row + 1
For i = 1 To LastRow
If Sheets("Sheet1").Range("B" & i).Text = "Good" Then
Sheets("Sheet1").Range("A" & i).Copy Destination:=Sheets("Sheet2").Range("A" & Row)
Sheets("Sheet1").Range("D" & i).Copy Destination:=Sheets("Sheet2").Range("D" & Row)
Sheets("Sheet1").Range("G" & i).Copy Destination:=Sheets("Sheet2").Range("G" & Row)
Row = Row + 1
End If
Next i

lucas
03-22-2006, 08:55 PM
Thats nice Jake and plenty of flexability. I'll have to yoink it

d_raghu9
03-22-2006, 09:19 PM
Thank You DRJ . I will try this and coule your please recommend any good book for VBA for excel for beginners. thank you for your help again.