Pushing data from userform to a specific row in a sheet

ananthkrish

New Member
Joined
Apr 27, 2019
Messages
4
I am new to VBA, please dont mind if my mistakes are blunder

I am trying to send the data from userform to a sheet, where there is a id in colom "A", and this data should go to the cells in that row.

i was using match and offset function,

below mentioned is the code i was trying.

please help

Private Sub Save_1_Click()​
'Dim i As Integer​
Sheet2.Activate​
Set i = Me.ID_Search​
Dim rng As Range​
Set rng = Sheets("sheet2").Range("A1").Offset(Application.WorksheetFunction.Match(i, Range("A:A"), 0), 2)​
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Re: Help me in pushing data from userform to a specific row in a sheet

Hi,
welcome to forum

Try this update to your code

Code:
Private Sub Save_1_Click()
    Dim RowNo As Variant
    Dim Search As String
    
    Search = Me.ID_Search.Text
    If Len(Search) = 0 Then Exit Sub
    
    With Worksheets("Sheet2")
        
        RowNo = Application.Match(Search, .Range("A:A"), 0)
        
        If Not IsError(RowNo) Then
            
'add records here
            .Cells(CLng(RowNo), 2).Value = Me.TextBox2.Text
            
        Else
'inform user
            MsgBox Search & Chr(10) & "Record Not Found", 48, "Not Found"
            
        End If
    End With
    
End Sub


Dave
 
Last edited:
Upvote 0
Re: Help me in pushing data from userform to a specific row in a sheet

Hi,

I have tried that, but not working.

my ID_Search is a Numeric, as we mentioned as .text will that be a reason for error?
 
Upvote 0
Re: Help me in pushing data from userform to a specific row in a sheet

Hi,

I have tried that, but not working.

my ID_Search is a Numeric, as we mentioned as .text will that be a reason for error?

Hi,
always worth mentioning things like that.

You need to coerce the string using one of the built in conversion functions

Rich (BB code):
RowNo = Application.Match(Val(Search), .Range("A:A"), 0)

Update code shown in red & see if helps

Dave
 
Upvote 0
Re: Help me in pushing data from userform to a specific row in a sheet

Hey dave,


i changed little and it worked, thank you so much..

Code:
Private Sub Save_1_Click()
        
 Dim RowNo As Variant
 Dim Search As Integer
 
    Search = Me.ID_Search.Value
    If Len(Search) = 0 Then Exit Sub
    
    With Worksheets("Sheet2")
        
    RowNo = Application.Match(Search, .Range("A:A"), 0)
        
    If Not IsError(RowNo) Then
           
'add records here
    .Cells(CLng(RowNo), 2).Value = Me.DTPicker1.Value
    .Cells(CLng(RowNo), 3).Value = Me.DTPicker2.Value
    .Cells(CLng(RowNo), 4).Value = Me.DTPicker3.Value
    .Cells(CLng(RowNo), 5).Value = Me.Block_1.Value
    .Cells(CLng(RowNo), 6).Value = Me.Floor_1.Value
    .Cells(CLng(RowNo), 7).Value = Me.Room_1.Value
    .Cells(CLng(RowNo), 8).Value = Me.Dept_1.Value
    .Cells(CLng(RowNo), 9).Value = Me.Req_by1.Value
    .Cells(CLng(RowNo), 10).Value = Me.Book_by1.Value
    Else
'inform user
    MsgBox Search & Chr(10) & "Record Not Found", 48, "Not Found"
    End If
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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