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
| Sub CopieValeursfinale()
Dim TheCell As Range, TheSheet As Worksheet
Dim OpenFile
Dim FichierSource As Workbook
Dim FichierDestin As Workbook
Dim TheColCell As Range
Set FichierSource = Workbooks("Draft budget model 8.xls")
OpenFile = Application.GetOpenFilename
If OpenFile <> False Then
Set FichierDestin = Application.Workbooks.Open(OpenFile)
Else
Exit Sub
End If
For Each TheSheet In FichierSource.Sheets
With TheSheet
For Each TheColCell In .Range("H1", .Cells(1, Columns.Count).End(xlToLeft))
If TheColCell = "1" Then
For Each TheCell In .Range("A2", .Cells(Rows.Count, "A").End(xlUp))
If TheCell = "1" Then
FichierDestin.Sheets(TheSheet.Name).Cells(TheCell.Row, TheColCell.Column) = .Cells(TheCell.Row, TheColCell.Column)
End If
Next
End If
Next
For Each TheColCell In .Range("h1", .Cells(1, Columns.Count).End(xlToLeft))
If TheColCell = "2" Then
For Each TheCell In .Range("A2", .Cells(Rows.Count, "A").End(xlUp))
If TheCell = "2" Then
FichierDestin.Sheets(TheSheet.Name).Cells(TheCell.Row, TheColCell.Column) = .Cells(TheCell.Row, TheColCell.Column)
End If
Next
End If
Next
For Each TheColCell In .Range("h1", .Cells(1, Columns.Count).End(xlToLeft))
If TheColCell = "2" Then
For Each TheCell In .Range("A2", .Cells(Rows.Count, "A").End(xlUp))
If TheCell = "1" Then
FichierDestin.Sheets(TheSheet.Name).Cells(TheCell.Row, TheColCell.Column) = .Cells(TheCell.Row, TheColCell.Column)
End If
Next
End If
Next
End With
Next
End Sub |