1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| Sub pcm_to_pdv()
Dim PDVrefobj As Object
Dim PCMobj As Object
Dim PDVobj As Object
Dim obj As Object
Dim test1 As Object
Dim lot_id As String
Dim s1 As String
Dim i As Integer
i = 0
Set PDVrefobj = Range(Cells(1, 1).End(xlDown), Cells(1, 1).End(xlToRight))
Application.Workbooks.Open (Application.GetOpenFilename)
Set PCMobj = Range(Cells(2, 1).End(xlDown), Cells(2, 1).End(xlToRight))
Set obj = PCMobj.Find(What:="lot_id", LookAt:=xlPart)
If Not (obj Is Nothing) Then
lot_id = PCMobj.Cells(obj.Row, obj.Column).Offset(5, 0).Value
Else
lot_id = "No_lot_id"
End If
PCMobj.EntireColumn.AutoFit
ActiveSheet.Name = lot_id
Sheets.Add After:=ActiveSheet
ActiveSheet.Name = lot_id & "_ok"
PCMobj.Copy (Cells(1, 1))
Set PCMobj = Range(Cells(1, 1).End(xlDown), Cells(1, 1).End(xlToRight))
Set obj = PCMobj.Range(Cells(1, 1), Cells(1, PCMobj.Columns.Count))
For Each thing In obj
If PCMobj.Cells(2, thing.Column).Value <> " " Then
If PCMobj.Cells(2, thing.Column).Value <> "" Then
If PCMobj.Cells(2, thing.Column).Value <> "Key" Then
thing.Value = PCMobj.Cells(2, thing.Column) & Chr(10) & PCMobj.Cells(3, thing.Column) & Chr(10) & PCMobj.Cells(4, thing.Column)
End If
End If
End If
Next
PCMobj.Rows(2).Delete: PCMobj.Rows(2).Delete: PCMobj.Rows(2).Delete:
PCMobj.Rows(1).VerticalAlignment = xlTop
PCMobj.Rows(1).AutoFit
PCMobj.EntireColumn.AutoFit
Set PDVobj = Range(Cells(1, PCMobj.Columns.Count + 1), Cells(PCMobj.Rows.Count, PCMobj.Columns.Count + 32))
i = i + 1
PDVobj.Cells(1, i).Value = PDVrefobj.Cells(i, 1).Value
Set test1 = PCMobj.Find(What:=PDVrefobj.Cells(i, 3).Value, LookAt:=xlPart)
If Not (test1 Is Nothing) Then
s1 = test1.Offset(1, 0).Address(RowAbsolute:=False)
PDVobj.Cells(2, i).Value = "=IF(ISBLANK(" & s1 & "),""""," & s1 & "/57)"
PDVobj.Cells(2, i).AutoFill Destination:=PDVobj.Range(Cells(2, i), Cells(PDVobj.Rows.Count, i)), Type:=xlFillDefault
Else
PDVobj.Cells(2, i).Value = "EAL00014 not found"
PDVobj.Cells(2, i).AutoFill Destination:=PDVobj.Range(Cells(2, i), Cells(PDVobj.Rows.Count, i)), Type:=xlFillDefault
End If
End Sub |
Partager