Probleme de range, ou de set ou autre?
Bonjour,
J´ai un soucis pour identifier ce qui n´est pas correctement ecrit dans ma macro.
Etant donné que le débuggeur ne me signale rien, et malgrès de nombreuses tentative de contourner le probleme, je suis toujours bloqué.
edit: Ah oui, le but de la procédure est de se balader dans diverses zones pour identifier où coller un résultat obtenu precedemment. Pour trouver le bon endroit, la macro utiliser des variables données par l´utilisateur (date, semaine, MSN) /edit
Je colle mon code, ou du moins, la procédure qui ne fonctionne pas correctement.
En fait, lorsque la macro arrive au 2eme "for each" ('identify pasteColumn)(ligne 39 ci dessous), le code suivant n´est pas executé.
Je pense que l´erreur se situe dans le range un qqch du genre.
J´ai tenté d´isoler le range dans une variable, d´utiliser set, mais cela n´a pas suffit.
Pouvez vous m´aider?
Code:
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
|
Option Explicit
Dim Path_Input_Workbook As String
Dim Input_Workbook As Workbook
Dim myYear As String
Dim myWeek As String
Dim myMSN As String
Dim myMSNdecimal As String
Dim lastRow As Long
Dim lastColumn As Long
Dim myCell As Range
Dim myRange As Range
Dim myWorkbook As String
Dim input_PivotTable As String
Dim output_PivotTable As String
Dim criteriaName As String
Dim subtotalValue As Long
Dim classified As String
Dim pasteSheet As String
Dim pasteColumn As Long
Dim pasteRow As Long
Dim yearRow As Long
Sub copyPaste()
If classified = True Then pasteSheet = "MSN" & myMSN & "_classified"
If classified = False Then pasteSheet = "MSN" & myMSN & "_not_classified" 'define sheet to paste
'search the row, according to the year
For Each myCell In Workbooks(myWorkbook).Worksheets(pasteSheet).Range("A:A")
If myCell = myYear Then
yearRow = myCell.Row
Exit For
End If
Next
'identify pasteColumn
For Each myCell In Workbooks(myWorkbook).Worksheets(pasteSheet).Range(Cells(yearRow, 1), Cells(yearRow, 53)) '53=52 weeks + first column title
If myCell = myWeek Then
pasteColumn = myCell.Column
Exit For
End If
Next
MsgBox "pasteColumn=" & pasteColumn
'identify pasteRow
For Each myCell In Workbooks(myWorkbook).Worksheets(pasteSheet).Range(Cells(yearRow, 1), Cells(yearRow + 7, 1)) 'yearRow+8 because of the 7 titles in column A
If myCell = criteriaName Then
pasteRow = myCell.Row
Exit For
End If
Next
MsgBox "pasteRow=" & pasteRow
'copypaste the result contained into variable "subtotalValue"
Workbooks(myWorkbook).Worksheets(pasteSheet).Cells(pasteRow, pasteColumn) = subtotalValue
End Sub |
Merci d´avance.