How to create a macro to control data flow

J

JW_4222

I need to create a macro to transfer info from one worksheet to another based
on the input of a certain cell.

Example of what I'm trying to do:

Workbook 1 Sheet 1:

A B C D

1 Name Type ID User

If Sheet 1 B3 = Blue, send data in row 3 to sheet 2, next availiable row,
and also to Sheet 4 next availiable row.

If Sheet 1 B3 = Green, send data in row 3 to sheet 3, next availiable row
and also Sheet 4 next availiable row.

And I am also creating sheet 5 to do some scheduling and tracking which I
can adjust the process as needed.

I'd appreciate any help.

Thanks,
 
V

vezerid

Sub copy2sheets()
Dim i As Long, j as long, s2row As Long, s3row As Long, s4row As Long
i = 2
s2row = 2
s3row = 2
s4row = 3
While Sheets("Sheet1").Cells(i, 1) <> ""
If Sheets("Sheet1").Cells(i, 2) = "Blue" Then
For j = 1 To 4
Sheets("Sheet2").Cells(s2row, j).Value =
Sheets("Sheet1").Cells(i, j).Value
Sheets("Sheet4").Cells(s4row, j).Value =
Sheets("Sheet1").Cells(i, j).Value
Next j
s2row = s2row + 1
s4row = s4row + 1
ElseIf Sheets("Sheet1").Cells(i, 2) = "Green" Then
For j = 1 To 4
Sheets("Sheet3").Cells(s3row, j).Value =
Sheets("Sheet1").Cells(i, j).Value
Sheets("Sheet4").Cells(s4row, j).Value =
Sheets("Sheet1").Cells(i, j).Value
Next j
s3row = s3row + 1
s4row = s4row + 1
End If
i = i + 1
Wend
End Sub

HTH
Kostis Vezerides
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top