"Runtime Error 91"
Solved
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 answers
-
Thank you for your replies.
And sorry for the oversight, but let him who is without sin cast the first stone.
I modified the line of code as you pointed out.
It still didn't work. After a flash of genius (or not), I copied the values from my column Z and pasted only the values, not the formulas. And now it works.
All I have left to do is modify my code so that column Z contains only text values automatically and not formulas.
Thank you all for the time you devoted to a clumsy novice.
Have a great day everyone.