ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   if multiple conditions are true, then copy the row to a new sheet (https://www.excelbanter.com/excel-programming/406044-if-multiple-conditions-true-then-copy-row-new-sheet.html)

Don Doan

if multiple conditions are true, then copy the row to a new sheet
 
Hi all,
I have a "master" spreadsheet and 3 other spreadsheets "Month","Vic", "Day"
all in the same workbook.
how can i create a macro that go through the "master" sheet and look at
column
D and E (in the same row) to find certain conditions:
if column D has "MVInd" and column E has the letter "M", then copy that row
to the spreadsheet "Month"
if column D has "COD" and column E has the letter "V", then copy that row to
the spreadsheet "Vic"
if column D has "OPTD" and column E has the letter "D", then copy that row
the spreadsheet "Day"
the macro should keep doing that until there is a blank row in the "master"
sheet.

Thank you very much.


joel

if multiple conditions are true, then copy the row to a new sheet
 
Sub test()

MonthRowCount = 1
VicRowCount = 1
DayRowCount = 1
RowCount = 1
With Sheets("Master")
Do While .Range("D" & RowCount) < ""
If .Range("D" & RowCount) = "MVInd" And .Range("E" & RowCount) = "M"
Then
.Rows(RowCount).Copy _
Destination:=Sheets("Month").Rows(MonthRowCount)
MonthRowCount = MonthRowCount + 1
End If
If .Range("D" & RowCount) = "COD" And .Range("E" & RowCount) = "V" Then
.Rows(RowCount).Copy _
Destination:=Sheets("Vic").Rows(VicRowCount)
VicRowCount = VicRowCount + 1
End If
If .Range("D" & RowCount) = "OPTD" And .Range("E" & RowCount) = "D" Then
.Rows(RowCount).Copy _
Destination:=Sheets("Day").Rows(DayRowCount)
DayRowCount = DayRowCount + 1
End If

RowCount = RowCount + 1
Loop
End With


End Sub


"Don Doan" wrote:

Hi all,
I have a "master" spreadsheet and 3 other spreadsheets "Month","Vic", "Day"
all in the same workbook.
how can i create a macro that go through the "master" sheet and look at
column
D and E (in the same row) to find certain conditions:
if column D has "MVInd" and column E has the letter "M", then copy that row
to the spreadsheet "Month"
if column D has "COD" and column E has the letter "V", then copy that row to
the spreadsheet "Vic"
if column D has "OPTD" and column E has the letter "D", then copy that row
the spreadsheet "Day"
the macro should keep doing that until there is a blank row in the "master"
sheet.

Thank you very much.


Don Doan

if multiple conditions are true, then copy the row to a new sh
 
thank you very much, it works perfectly.

"Joel" wrote:

Sub test()

MonthRowCount = 1
VicRowCount = 1
DayRowCount = 1
RowCount = 1
With Sheets("Master")
Do While .Range("D" & RowCount) < ""
If .Range("D" & RowCount) = "MVInd" And .Range("E" & RowCount) = "M"
Then
.Rows(RowCount).Copy _
Destination:=Sheets("Month").Rows(MonthRowCount)
MonthRowCount = MonthRowCount + 1
End If
If .Range("D" & RowCount) = "COD" And .Range("E" & RowCount) = "V" Then
.Rows(RowCount).Copy _
Destination:=Sheets("Vic").Rows(VicRowCount)
VicRowCount = VicRowCount + 1
End If
If .Range("D" & RowCount) = "OPTD" And .Range("E" & RowCount) = "D" Then
.Rows(RowCount).Copy _
Destination:=Sheets("Day").Rows(DayRowCount)
DayRowCount = DayRowCount + 1
End If

RowCount = RowCount + 1
Loop
End With


End Sub


"Don Doan" wrote:

Hi all,
I have a "master" spreadsheet and 3 other spreadsheets "Month","Vic", "Day"
all in the same workbook.
how can i create a macro that go through the "master" sheet and look at
column
D and E (in the same row) to find certain conditions:
if column D has "MVInd" and column E has the letter "M", then copy that row
to the spreadsheet "Month"
if column D has "COD" and column E has the letter "V", then copy that row to
the spreadsheet "Vic"
if column D has "OPTD" and column E has the letter "D", then copy that row
the spreadsheet "Day"
the macro should keep doing that until there is a blank row in the "master"
sheet.

Thank you very much.



All times are GMT +1. The time now is 04:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com