Using InputBox to selectively place data into the specified Row

Tarkemelion

New Member
Joined
Jun 28, 2022
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a button that leads to a UserForm where the User enters in some information and is prompted with an InputBox. The intention is that the user types in the row that they want the aforementioned UserForm information to be placed. I seem to be struggling with transferring the row entered into the InputBox as a value which can then be used. Feedback and advice is appreciated!

VBA Code:
Private Sub cmdAdd_Click()

'Define the variables
    Dim Invoice_Number As String
    Dim Invoice_Value As String
    
    Dim Ret1 As Long
    Dim lRow As Range
        
    Dim ws As Worksheet
    
'Sets variables to UserForm values
    Invoice_Number = TextBox1.Text
    Invoice_Value = TextBox2.Text
    
Set ws = ThisWorkbook.Worksheets("Cost Detail")

Set tbl = ws.ListObjects("Table1")

'Specify row to add information
    On Error Resume Next
    Ret1 = Application.InputBox("Which Docket is associated with the Invoice", "Add Invoice")
    On Error GoTo 0
    
    
'Add information if row is associated with a docket
    If lRow > 18 Then
        With lRow
            .Range(14) = Invoice_Number
            .Range(15) = Invoice_Value
        End With
    ElseIf Ret1 <= 18 Then
        MsgBox "This is not a docket row!!!"
        
    End If
    
'Closes UserForm
    Unload Me

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Quick note since posting; I realise the variable "Ret1" was used inappropriately in the "ElseIf" line. This may have been when I was fiddling around with variable names and forgot to change it back. Even if it was replaced with "lRow", the code still needs help!
 
Upvote 0

Forum statistics

Threads
1,223,881
Messages
6,175,159
Members
452,615
Latest member
bogeys2birdies

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