Storing Data from User Form to Excel Sheet

shreyas17

New Member
Joined
Jul 22, 2021
Messages
17
Office Version
  1. 2016
Platform
  1. Windows
Hi Everyone,

I have created a user form and have a submit button such that whenever the submit button is clicked the data get automatically stored column wise in another worksheet of the same workbook. I have written the below code. However, each time I click on the submit button the data gets replaced by the new one , I want it to keep adding data into the next rows.

Private Sub CommandButton10_Click()

Dim msgValue As VbMsgBoxResult

msgValue = MsgBox("Do you want to save the data?", vbYesNo + vbInformation, "Confirmation")

If msgValue = vbNo Then Exit Sub

Dim wkdatabse As Worksheet
Dim Adddatabse As Range

Set wkdatabse = Sheet4

Set Adddatabse = wkdatabse.Range("A65365").End(xlUp).Offset(1, 0)


Adddatabse.Offset(0, 1).Value = TextBox10.Text
Adddatabse.Offset(0, 2).Value = TextBox3.Text
Adddatabse.Offset(0, 3).Value = TextBox7.Text

how to I change this to add value continuously to the rows without getting overwrite
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi,
see if this update to your code helps

VBA Code:
Private Sub CommandButton10_Click()
    
    Dim wkdatabse   As Worksheet
    Dim AddDatabse  As Range
    Dim msgValue    As VbMsgBoxResult
    
    msgValue = MsgBox("Do you want To save the data?", vbYesNo + vbInformation, "Confirmation")
    
    If msgValue = vbNo Then Exit Sub
    
    Set wkdatabse = Sheet4
    
    Set AddDatabse = wkdatabse.Cells(wkdatabse.UsedRange.Rows.Count + 1, 1)
    
    With AddDatabse
        .Offset(0, 1).Value = TextBox10.Text
        .Offset(0, 2).Value = TextBox3.Text
        .Offset(0, 3).Value = TextBox7.Text
    End With
End Sub

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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