cut paste according cell value if row is not hidden

Flavien

Board Regular
Joined
Jan 8, 2023
Messages
55
Office Version
  1. 365
Platform
  1. Windows
Hello Every body.

My workbook is composed of 2 sheets.
Sheet 1, I would like to cut rows (only cells of columns A,B,C,E,F) according to a value written on the column G, only if the row is not hidden (filter on column A), then paste cells on the last row of the sheet2 on the columns A,B,C,D,G.
To finish, I'd like to replace the value written in G with "x" and display a message box.

Unfortunately, my macro doesn't work, it copy the head of the first chart on the second line of the second chart. :(

Sub Transfert()

Dim lig As Long, i As Long
Dim ws1 As Worksheet, ws2 As Worksheet
Dim c As Range
Dim j As Long


Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set ws1 = Worksheets("POLKA")
Set ws2 = Worksheets("SUIVI")
lig = 2

With ws1

For i = 2 To ws1.Range("A" & Rows.Count).End(xlUp).Row
If Not .Rows(i).Hidden Then

If ws1.Cells(i, 7) = "En cours" Then


ws1.Cells(1, "A").Cut ws2.Cells(lig, "A")
ws1.Cells(1, "B").Cut ws2.Cells(lig, "B")
ws1.Cells(1, "C").Cut ws2.Cells(lig, "C")
ws1.Cells(1, "E").Cut ws2.Cells(lig, "D")
ws1.Cells(1, "F").Cut ws2.Cells(lig, "G")

lig = Cells(Rows.Count, 1).End(xlUp).Row

End If

End If

Next i

End With

Worksheets("POLKA").Columns("G").Replace what:="En cours", replacement:="x", lookat:=xlPart

MsgBox "Transfert terminé"

Application.ScreenUpdating = False
Application.DisplayAlerts = False


End Sub

02 - GESTIONNAIRE DES PCP - 01-02-23B.xlsm
ABCDEFGH
1N° de plan / GCUIndice Plan GCUDésignation articlePiloteDésignation de l'actionNos BesoinsDate de lancementEtat d'avancement
2Colonne1Colonne2Colonne3Colonne4Colonne5
33431AMaillon latéral fermoir 3R BraceletflaCréer PCP07/12/20225
43434AAXE EPAULE FERMOIR BRACELET flaCréer PCP23/01/2023
53435CAXE EPAULE STANDARD BRACELET flaCréer PCP23/01/2023
63436CAXE PIVOT FERMOIRflaCréer PCP19/12/202240
73437AVIS DE RALLONGE ENCOLLE BRACELET flaCréer PCP23/01/2023
83466DDESSOUS FERMOIR -bracelet montre mini flaCréer PCP21/12/202240
93607BBague H d'ancre lightfla
103618AAlliance gravée 40/10è 1DTflaCréer PCP01/12/202275
115135CMotif rose des vents PM 8 mm - reprise usinageflaCréer PCP03/01/20221
126129Amotif bracelet rose des vents 12 mm - reprise usinageflaCréer PCP Harmoniser cotes critiques selon motif Ø8 mm (prof 1,14 & 0,5)Posage de contrôle21/11/22250
SUIVI
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H2:H45Other TypeDataBarNO
B5Expression=#REF!="FAUX"textNO
B5Expression=#REF!="VRAI"textNO


02 - GESTIONNAIRE DES PCP - 01-02-23B.xlsm
ABCDEFG
1Colonne1Colonne2Colonne3Sous-familleColonne4Colonne5igine de l'article
27485BSUPPT LAME FERMOIR BRACELET SFFla03/02/2023En cours
37486FLAME FERMOIR BRACELET OG H1 SFFla03/02/2023En cours
47487BFAUX DE SECURITE PAVE FERMOIR BRACELET SFFla03/02/2023x
57488BBOITIER INFERIEUR FERMOIR BRACELET SFFla03/02/2023
67489BBOITIER SUPERIEUR FERMOIR BRACELET SFFla03/02/2023
77491BSERTISSURE CENTRE 3 BRILLANT FERMOIR BRACELET SFFla03/02/2023
87492ASERTISSURE CENTRE TTO FERMOIR BRACELET SFFla03/02/2023x
97494BSERTISSURE BOUT 3 BRILLANT FERMOIR BRACELET SFFla03/02/2023x
107495ASERTISSURE BOUT TTO FERMOIR BRACELET SFFla03/02/2023x
117496AGOUPILLE AXE DE FAUX FERMOIR BRACELET SFFla03/02/2023x
127497AGOUPILLE CLIP DE FAUX FERMOIR BRACELET SFFla03/02/2023x
137621BPIECE DE POUCE 3 BRILLANT FERMOIR BRACELET SFFla03/02/2023
147811BPIECE DE POUCE TOUT FERMOIR BRACELET SFFla03/02/2023
157843BFAUX DE SECURITE TTO FERMOIR BRACELET SFFla03/02/2023x
1610117ADESSUS SERTISSURE RONDE BRILLANT BRACELET OG_PROTO SFFla03/02/2023x
1710118ADESSUS SERTISSURE RONDE LIAISON ENTRE CNE BRILLANT BRACELET OG_PROTO SFFla03/02/2023x
187811BPIECE DE POUCE TOUT FERMOIR BRACELET SFFla03/02/2023x
POLKA
Cell Formulas
RangeFormula
A18A18=TEXTJOIN("",TRUE,IFERROR((MID(H18,ROW(INDIRECT("1:"&LEN(H18))),1)*1),""))
B18B18=RIGHT(H18,1)
F2:F18F2=TODAY()
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
From what I can tell, you are looping through ws1 for "En cours" but "En cours", is in ws2
 
Upvote 0
From what I can tell, you are looping through ws1 for "En cours" but "En cours", is in ws2
Thank you for your advice!!
I replaced WS1 with WS2.... But the macro sticks the cut cells always on row 2. What am I doing wrong?

Sub Transfert()

Dim lig As Long, i As Long
Dim ws1 As Worksheet, ws2 As Worksheet


Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set ws1 = Worksheets("SUIVI")
Set ws2 = Worksheets("POLKA")
lig = 2

With ws2

For i = 2 To ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
If Not .Rows(i).Hidden Then

If ws2.Cells(i, 7) = "En cours" Then


ws2.Cells(i, "A").Cut ws1.Cells(lig, "A")
ws2.Cells(i, "B").Cut ws1.Cells(lig, "B")
ws2.Cells(i, "C").Cut ws1.Cells(lig, "C")
ws2.Cells(i, "E").Cut ws1.Cells(lig, "D")
ws2.Cells(i, "F").Cut ws1.Cells(lig, "G")

lig = lig + 1


End If

End If

Next i

End With

Worksheets("POLKA").Columns("G").Replace what:="En cours", replacement:="x", lookat:=xlPart

MsgBox "Transfert terminé"

Application.ScreenUpdating = False
Application.DisplayAlerts = False


End Sub
 
Upvote 0
Finaly I have replaced:
"lig = 2" by "lig = ws1.Range("A" & Rows.Count).End(xlUp).Row + 1"

and deleted "lig = lig + 1"

Thank you again Davesexcel for your help!!!
 
Upvote 0
@davesexcel : Hello Daves,

I've one more question:
The macro turns all "In progress" cells into "x" even hidden lines. Do you have a solution?
 
Upvote 0
Hello @Peter_SSs , I allow myself to ask you because I did not find an answer to my question. Could you help me please ?
The macro turns all "In progress" cells into "x" even hidden lines. Do you have a solution?
 
Upvote 0

Forum statistics

Threads
1,216,031
Messages
6,128,424
Members
449,450
Latest member
gunars

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top