Userform new entries

Desertbird

New Member
Joined
Jul 21, 2021
Messages
16
Office Version
  1. 2016
Platform
  1. Windows
  2. Mobile
Hello,
I'm using the below code for a userform that adds items to a dataset. However it is not adding a new row and instead is replacing the row. I tried putting this together based off of the below youtube video, but I'm not sure what I'm doing wrong and why it's not working. Any advice would be helpful at this point, thank you!



Private Sub CommandButton1_Click()

Dim TargetRow As Integer

TargetRow = Sheets("Engine").Range("B5").Value

Sheets("data").Range("DataStart").Offset(TargetRow, 1).Value = SupName
Sheets("data").Range("DataStart").Offset(TargetRow, 2).Value = AgentName
Sheets("data").Range("DataStart").Offset(TargetRow, 3).Value = Dates
Sheets("data").Range("DataStart").Offset(TargetRow, 4).Value = Reason
Sheets("data").Range("DataStart").Offset(TargetRow, 5).Value = Types
Sheets("data").Range("DataStart").Offset(TargetRow, 6).Value = Method
Sheets("data").Range("DataStart").Offset(TargetRow, 7).Value = Discussion
Sheets("data").Range("DataStart").Offset(TargetRow, 8).Value = Followup

Unload DLOGDASHBOARD

End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
The following should work as desired. You will not need to use B5 for anything.

VBA Code:
Private Sub CommandButton1_Click()

Dim ws As Worksheet
Set ws = ActiveSheet
Dim newRow As Long

newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1

Sheets("data").Range("DataStart").Offset(newRow, 1).Value = SupName
Sheets("data").Range("DataStart").Offset(newRow, 2).Value = AgentName
Sheets("data").Range("DataStart").Offset(newRow, 3).Value = Dates
Sheets("data").Range("DataStart").Offset(newRow, 4).Value = Reason
Sheets("data").Range("DataStart").Offset(newRow, 5).Value = Types
Sheets("data").Range("DataStart").Offset(newRow, 6).Value = Method
Sheets("data").Range("DataStart").Offset(newRow, 7).Value = Discussion
Sheets("data").Range("DataStart").Offset(newRow, 8).Value = Followup

Unload DLOGDASHBOARD

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,602
Members
449,089
Latest member
Motoracer88

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