"Runtime Error 91"
Solved
Amande42
Posted messages
26
Status
Membre
-
Amande42 Posted messages 26 Status Membre -
Amande42 Posted messages 26 Status Membre -
Hello everyone,
And thank you in advance to those who will look into my problem, I'm on the verge of tears in front of my screen or ready to throw it against the wall... ;-)
I'm still working on the same tool, progressing slowly but surely.
Today's problem: the aim of this code is to find the "Valcherchée" (concatenation of 3 cells located in the "MàJ PA - retour audités" sheet) in column Z of the "BDD résumé" sheet. I've checked via a MsgBox and "Valcherchée" is indeed what I'm trying to find.
From there and using the offset method that should point to column G, find the cell indicating the associated campaign number for the "Valcherchée" and replace it with the number entered in the "MàJ PA - retour audités" sheet (updating the campaign number for each mission every 6 months).
I tested my procedure yesterday and after a day of working on it, it finally worked when I left in the evening. But, as always, this morning it stopped working. I've tried to improve it based on online suggestions, but after 3 hours on it, nothing works and I've given up!
While stepping through my procedure, it crashes at "MsgBox Cellule" (I added this line to try to identify the problem) and error message 91 appears. However, I don't have a with without end with (I tried putting one just in case), my variables are declared (I tried making them Variant to see if that solved my issue...), etc.
If I remove the code line "MsgBox Cellule", the procedure continues and returns Nothing, my MsgBox "Non trouvé" appears and the process ends.
What I don't understand is that my "Valcherchée" is indeed present in my column Z.
I'm cracking up!! No more patience.
Thank you in advance for your valuable help.
Have a nice day everyone.
Amande42
PS: how do you format code on this forum (boxed and colored) to facilitate reading?
And thank you in advance to those who will look into my problem, I'm on the verge of tears in front of my screen or ready to throw it against the wall... ;-)
I'm still working on the same tool, progressing slowly but surely.
Today's problem: the aim of this code is to find the "Valcherchée" (concatenation of 3 cells located in the "MàJ PA - retour audités" sheet) in column Z of the "BDD résumé" sheet. I've checked via a MsgBox and "Valcherchée" is indeed what I'm trying to find.
From there and using the offset method that should point to column G, find the cell indicating the associated campaign number for the "Valcherchée" and replace it with the number entered in the "MàJ PA - retour audités" sheet (updating the campaign number for each mission every 6 months).
I tested my procedure yesterday and after a day of working on it, it finally worked when I left in the evening. But, as always, this morning it stopped working. I've tried to improve it based on online suggestions, but after 3 hours on it, nothing works and I've given up!
While stepping through my procedure, it crashes at "MsgBox Cellule" (I added this line to try to identify the problem) and error message 91 appears. However, I don't have a with without end with (I tried putting one just in case), my variables are declared (I tried making them Variant to see if that solved my issue...), etc.
If I remove the code line "MsgBox Cellule", the procedure continues and returns Nothing, my MsgBox "Non trouvé" appears and the process ends.
What I don't understand is that my "Valcherchée" is indeed present in my column Z.
Private Sub MAJNumCampagne() 'SEARCH CELL WITH CAMPAIGN NUMBER CORRESPONDING TO THE SELECTED MISSION IN THE "BDD résumé" SHEET Dim Valcherchée As String Dim Cellule As Range 'cell containing the 3 concatenated search values Dim myRange As Range 'cell corresponding to the campaign number 'Concatenation Mission + Year + Entity to search With Sheets("MàJ PA - retour audités") Valcherchée = .Range("D6").Value & .Range("G8").Value & .Range("D10").Value End With 'Activating the cell containing the campaign number based on the mission and assigning the updated number Set Cellule = Sheets("BDD résumé").Columns(26).Find(Valcherchée, Lookat:=xlWhole) MsgBox Cellule If Cellule Is Nothing Then MsgBox "Non trouvé." Exit Sub End If If Not Cellule Is Nothing Then myRange = Cellule.Offset(, -19) myRange.Value = Sheets("MàJ PA - retour audités").Range("I17").Value End If End Sub I'm cracking up!! No more patience.
Thank you in advance for your valuable help.
Have a nice day everyone.
Amande42
PS: how do you format code on this forum (boxed and colored) to facilitate reading?
| EDIT: Added code tags (syntax highlighting). Explanations available here: HERE Thank you for keeping this in mind in your future messages. |
8 réponses
Hello,
- To include code:
Explanations available here:
https://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code
- Regarding the error on the line of code:
.... since you declare your variable like this:
... Cellule ... is a "RANGE" (a range of cells or a single cell...)
So... this "object" contains a VALUE property (to get its content...) , an ADDRESS property (to know its coordinates.....) ... anyway... it's up to you to choose what you want to display.
You could therefore write:
Then you indicate:
... but... is the text present AS IS in your cell... or is it part of a TEXT contained in your cell???
As a reminder: xlWhole corresponds to => EXACT MATCH.
And finally ....
=> Do not use ACCENTED characters in the names of your variables!
(nor any special characters... (except underscores))
--
Best regards,
Jordane
- To include code:
Explanations available here:
https://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code
- Regarding the error on the line of code:
MsgBox Cellule
.... since you declare your variable like this:
Dim Cellule As Range
... Cellule ... is a "RANGE" (a range of cells or a single cell...)
So... this "object" contains a VALUE property (to get its content...) , an ADDRESS property (to know its coordinates.....) ... anyway... it's up to you to choose what you want to display.
You could therefore write:
Set Cellule = Sheets("BDD résumé").Columns(26).Find(Valcherchée, Lookat:=xlWhole) MsgBox Cellule If Cellule Is Nothing Then MsgBox "Not found." Exit Sub else MsgBox Cellule.Address myRange = Cellule.Offset(, -19) myRange.Value = Sheets("MàJ PA - retour audités").Range("I17").Value End If Then you indicate:
my "Valcherchée" is indeed present in my column Z.
... but... is the text present AS IS in your cell... or is it part of a TEXT contained in your cell???
As a reminder: xlWhole corresponds to => EXACT MATCH.
And finally ....
=> Do not use ACCENTED characters in the names of your variables!
(nor any special characters... (except underscores))
--
Best regards,
Jordane