Getting run-time error using User Form

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
774
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings,

I think I've gotten closer; however I'm getting a "run time error" followed by a long number. In the same error messge box I get "Method 'Value' of object out of 'Range' failed.

I changed the first column to a Custom Format to a "dd mmm yy". I have a Header Row in Row 1. I have a total 6 columns, but only the first five I need the User Form for. The last column is just the day of the month. (For a Pivot Table).

VBA Code:
Sub Submit()

Dim sh As Worksheet
Dim iRow As Long

Set sh = ThisWorkbook.Sheets("Activity")

iRow = [Counta(Activity!A:A)] + 1

With sh

     .Cells(iRow, 1).Value = CDate(frmForm.Txtdate)
     .Cells(iRow, 2) = frmForm.Txtmsn.Value
     .Cells(iRow, 3) = frmForm.Cmbmode.Value
     .Cells(iRow, 4) = frmForm.Cmbdentonfms.Value
     .Cells(iRow, 5) = frmForm.Txtweight.Value
     
    
  End With


End Sub

Thank you,
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
On which line are you getting the error?

BTW do you still get the error if you replace

VBA Code:
iRow = [Counta(Activity!A:A)] + 1

with

VBA Code:
iRow = sh.Range("A" & sh.Rows.Count).End(xlUp).Row + 1
 
Upvote 0
On which line are you getting the error?

BTW do you still get the error if you replace

VBA Code:
iRow = [Counta(Activity!A:A)] + 1

with

VBA Code:
iRow = sh.Range("A" & sh.Rows.Count).End(xlUp).Row + 1
I'm getting an error on the first line
Excel Formula:
 .Cells(iRow, 1).Value = CDate(frmForm.Txtdate)
 
Upvote 0
On which line are you getting the error?

BTW do you still get the error if you replace

VBA Code:
iRow = [Counta(Activity!A:A)] + 1

with

VBA Code:
iRow = sh.Range("A" & sh.Rows.Count).End(xlUp).Row + 1
I did try tha solution you made and I get the same thing.
 
Upvote 0
If you place this line of code just above that line returning the error, what does it return when you try to run the code?
VBA Code:
MsgBox frmForm.Txtdate
 
Upvote 0
If you place this line of code just above that line returning the error, what does it return when you try to run the code?
VBA Code:
MsgBox frmForm.Txtdate
Strange it displays 19 Aug 22 which is what I typed in on the User Form. When select ok on the message box I get the Run-time error the same error as before. When I select the Debug. I get another messaage which is an automation error. "The Object invoked has disconnected from it's clients". Excel wil shut down and reopen.
 
Upvote 0
Strange it displays 19 Aug 22 which is what I typed in on the User Form. When select ok on the message box I get the Run-time error the same error as before. When I select the Debug. I get another messaage which is an automation error. "The Object invoked has disconnected from it's clients". Excel wil shut down and reopen.
Hmmm, sounds like the issue is with something outside of this code.
Maybe the connection (if you are linking/connecting to other data sources).
Or perhaps you have an corruption issue.
 
Upvote 0
Strange it displays 19 Aug 22 which is what I typed in on the User Form. When select ok on the message box I get the Run-time error the same error as before.

try this update to your code & see if resolves your issue but if not & as already suggested, you may have other issues like file corruption going on

Code:
Sub Submit()
    Dim sh          As Worksheet
    Dim iRow        As Long
    
    Set sh = ThisWorkbook.Worksheets("Activity")
    
    iRow = sh.Cells(sh.Rows.Count, "A").End(xlUp).Row + 1
    
    With Me.txtdate
        If Not IsDate(.Value) Then .Value = Date
    End With
    
    With sh
        
        With .Cells(iRow, 1)
            .Value = DateValue(Me.txtdate.Value)
            .NumberFormat = "dd mmm yy"
        End With
        
        .Cells(iRow, 2) = Me.Txtmsn.Value
        .Cells(iRow, 3) = Me.Cmbmode.Value
        .Cells(iRow, 4) = Me.Cmbdentonfms.Value
        .Cells(iRow, 5) = Me.Txtweight.Value
    End With
    
    MsgBox "Record Submitted", 64, "Submitted"
    
End Sub

Note I have replaced your userform name with ME keyword as I assume that the code is in your userforms code page?

Dave
 
Upvote 0
try this update to your code & see if resolves your issue but if not & as already suggested, you may have other issues like file corruption going on

Code:
Sub Submit()
    Dim sh          As Worksheet
    Dim iRow        As Long
   
    Set sh = ThisWorkbook.Worksheets("Activity")
   
    iRow = sh.Cells(sh.Rows.Count, "A").End(xlUp).Row + 1
   
    With Me.txtdate
        If Not IsDate(.Value) Then .Value = Date
    End With
   
    With sh
       
        With .Cells(iRow, 1)
            .Value = DateValue(Me.txtdate.Value)
            .NumberFormat = "dd mmm yy"
        End With
       
        .Cells(iRow, 2) = Me.Txtmsn.Value
        .Cells(iRow, 3) = Me.Cmbmode.Value
        .Cells(iRow, 4) = Me.Cmbdentonfms.Value
        .Cells(iRow, 5) = Me.Txtweight.Value
    End With
   
    MsgBox "Record Submitted", 64, "Submitted"
   
End Sub

Note I have replaced your userform name with ME keyword as I assume that the code is in your userforms code page?

Dave
I tried that, why would I need to change the frm.form to .me? Thank you,
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top