• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

vba crashing after same number of actions on P c and tablet

Brian Ardent

New Member
I am recording car registration number plates into a sheet. The codes crashes after 31 recordings on boththe pc and a tablet.
There is nothing in the cell which the code is writing to. It crashes but has saved the work book as required by the line before it crashes.
The crash is happening on Userform1.Show. It does this operation 30 previous times but then decides to crash. Restart excel and using code to load the saved form and you can then continue recording line 31 without it crashing but on recording the 60th plate it crashesd again - Any suggestions
 
Hi Vletm

sample code below
>>> use code - tags <<<
Code:
Dim ws As Worksheet
Sheets("details").Unprotect Password:="Holden10"
Sheets("details").Select
Range("A4").Select
ActiveCell.Select
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col1
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
col1:
ActiveCell.Offset(1, 0).Select
ActiveCell.Select
If ActiveCell.Value = "columnend1" Then GoTo Col2 Else GoTo CoL12Next
CoL12Next:
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col1
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
It simply writes the text box value into a blank cell after testing - when the column is full by reading column1end it goes to the next column in the sheet to write. each column is 33 rows .
 
With Your code and sample data with an Excel-file Your could get smoother replies.

You sent part of code.
 
Hivietm,

The complete code for the operation is below.

>>> use - code tags <<
Code:
Private Sub recorddriver_Click()
Dim ws As Worksheet
Sheets("details").Unprotect Password:="Holden10"
Sheets("details").Select
Range("A4").Select
ActiveCell.Select
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col1
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
col1:
ActiveCell.Offset(1, 0).Select
ActiveCell.Select
If ActiveCell.Value = "columnend1" Then GoTo Col2 Else GoTo CoL12Next
CoL12Next:
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col1
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
Col2:
Range("D4").Select
ActiveCell.Select
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col2Next
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
col2Next:
ActiveCell.Offset(1, 0).Select
ActiveCell.Select
If ActiveCell.Value = "columnend2" Then GoTo Col3 Else GoTo Colm2nexT
Colm2nexT:
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col2Next
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
Col3:
Range("A51").Select
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col3Next
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
col3Next:
ActiveCell.Offset(1, 0).Select
ActiveCell.Select
If ActiveCell.Value = "columnend3" Then GoTo Col4 Else GoTo Colm3nexT
Colm3nexT:
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col3Next
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
Col4:
Range("D51").Select
ActiveCell.Select
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col4Next
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
col4Next:
ActiveCell.Offset(1, 0).Select
ActiveCell.Select
If ActiveCell.Value = "columnend4" Then GoTo Col5 Else GoTo Colm4nexT
Colm4nexT:
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col4Next
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
Col5:
Range("A100").Select
ActiveCell.Select
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col5Next
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
col5Next:
ActiveCell.Offset(1, 0).Select
ActiveCell.Select
If ActiveCell.Value = "columnend5" Then GoTo Col6 Else GoTo Colm5nexT
Colm5nexT:
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col5Next
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
Col6:
Range("D100").Select
ActiveCell.Select
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col6Next
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
col6Next:
ActiveCell.Offset(1, 0).Select
ActiveCell.Select
If ActiveCell.Value = "columnend6" Then GoTo Col7 Else GoTo Colm6nexT
Colm6nexT:
If ActiveCell.Value = "" Then ActiveCell.Value = UserForm3.driver.Value Else GoTo col6Next
ActiveCell.Offset(0, 1).Value = UserForm3.rego.Value
GoTo Col7
Col7:
Unload Me
Sheets("details").Protect Password:="Holden10"
UserForm1.Show
End Sub
 
Last edited by a moderator:
You seems to skip that underlined part.

Brian Ardent

I tried to refer to my #4 reply.
Screenshot 2024-08-26 at 11.27.35.png
Without a sample Excel-file, it would be challenge to verify Your case.
 
Last edited:
Yes, supply a workbook with this in it. There are lots of questions which will be answered by seeing that: What module is the code in? what is the Me referring to? what's on sheet details? what is Userform3 and what's on it? what is Userform1 and what's on it? are these userforms modeless? and more…
We can guess (there's a lot to guess) but we'd probably guess wrongly and any answers based on those guesses would likely be useless to you.

Apart from that, your code is best described as spaghetti!

Your code could be replaced with:
Code:
Private Sub recorddriver_Click()
With Sheets("details")
  .Unprotect Password:="Holden10"
  For Each cll In .Range("A4:A9,D4:D9,A51:A56,D51:D56,A100:A105,D100:D105") ' adjust this line
    If cll.Value = "" Then
      cll.Value = UserForm3.driver.Value
      cll.Offset(, 1).Value = UserForm3.rego.Value
      Exit For
    End If
  Next cll
  .Protect Password:="Holden10"
End With
Unload Me
'UserForm1.Show
End Sub
(and it could be shorter).
The part .Range("A4:A9,D4:D9,A51:A56,D51:D56,A100:A105,D100:D105") is the cells you want to check (where you want to place your data), in order. I've guessed at 6 rows each but that's probably wrong, so you'll need to put that right (the bits in red). You won't then need the likes of "columnend1" on the sheet.
I've commented out the Userform1.Show line as you say this causes a crash, but I have no way of knowing what causes the crash until I see the workbook.
 
Last edited:
Back
Top