Context:Hello,
When launching the attached code I get an error message: "Compile error: invalid next control variable reference".
Can you please help me?
Thanks,
Franck
Here is the Excel filePost an excel example, not a PDF.
Here is the requested fileNot only your code, an excel example with your 2 sheets with some dummy data.
Many thanks @Belleke!It is a bit of work to adjust everything to a good working file, but I am retired, I have time, In a few days you get an good working example.
wsForm.Range("C5:C10, CC14:C17, C22, C27:C28, C32:C34, C39:C44, C48:C50, C53:C56, C60:C61").ClearContents
@p45cal Meanwhile solvedHello @p45cal, many thanks for what you have done for me.
I have enabled macros on the file you sent back to me.
When trying to run the macro I get this error message: "Cannot run the macro "Chandoo55539Historical Incident management template - final version - testb'!ButtonOK_Click'. The macro may not be available in this workbook or all macros may be disabled"
Can you please help me?
Thanks
'Set new value to the cell in wsForm.Range("C5") after the clearing
wsForm.Range("C5") = wsForm.Range("C5") + 1
End Sub
Dear @p45cal and @Belleke,
The form has been updated and works as I want thanks to your contribution.
However I have another request to improve it:
I would like to add a new line that makes the first field of the form "Incident_id" automatically increment after the button "OK" has been pushed, the data have been successfully added to the next worksheet, and the content of the form has been cleared.
Are these lines correct - to be added at the end of the code?
Code:'Set new value to the cell in wsForm.Range("C5") after the clearing wsForm.Range("C5") = wsForm.Range("C5") + 1 End Sub
'This declares the data type of the variable "Incident_id" in wsForm.Range("C5")
Dim LstRw As Long
'This defines what the variable "Incident_id" in wsForm.Range("C5") is refer to
LstRow = wsDatabase.Cells(Rows.Count, "A").End(x1Up).Row
'This tells the textbox named ID to equal the value of the last used cell in column A from wsDatabase + 1
wsForm.Range("C5") = Cells(LstRw, "A").Value + 1
''' When executing the whole code, this message is displayed:
''' "Run-time error '1004': Application-defined or object-defined error'
''' and when clicking on the button "Debug" the following line is highlighted in yellow:
''' "LstRow = wsDatabase.Cells(Rows.Count, "A").End(x1Up).Row"