lundi 6 mai 2019

(Copy if) Multiple Variables

I wanted to copy data from one sheet to another. The selection part is according to date and specific value of column.

Name Type Date Stock DOWNY S.FRESH 900ML Fabricare 14-Apr-19 40 PANTENE SHP HFC 210 ML Haircare 14-Apr-19 30 DOWNY MYSTIQUE 800ML Fabricare 14-Apr-19 20 DOWNY MISTIQUE 230 ML Fabricare 14-Apr-19 0 PANTENE SHP HFC 210 ML Haircare 14-Apr-19 20 H&S SHP MNT DINGIN 170 ML Gondola 14-Apr-19 20 REJOICE SHP PARFUM SEGAR 170ML Gondola 14-Apr-19 20 REJOICE SHP PARFUM LEMBUT 170ML Gondola 14-Apr-19 22 DOWNY S.FRESH 900ML Fabricare 13-Apr-19 21

I tried this code from internet. So the basic logic is if 2 condition are met then copy the row. However its not working.

It actually working first when only one condition are written, when the second one written, the VBA did not do anything

Sub CopyRowsAcross() Dim i As Integer Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Clean_Sheet") Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Sheets("Daily_Report")

For i = 2 To ws1.Range("P65536").End(xlUp).Row If ws1.Cells(i, 1) = "DOWNY S.FRESH 900ML" and ws2.Range ("C2") = ws1.Cells(i,3) Then ws1.Rows(i).Copy ws2.Rows(ws2.Cells(ws2.Rows.Count, 2).End(xlUp).Row + 1) End If Next i End Sub

the ws2.Range("C2") are selected date written in cell C2 in the sheet.

The result are the row copied based on this 2 criteria

Aucun commentaire:

Enregistrer un commentaire