User Form Help required please

cmerrick

Board Regular
Joined
Jun 8, 2017
Messages
78
Office Version
  1. 365
Platform
  1. Windows
Hi all,

So I've recently started to use VBA and I need some help please.

I have a VBA code that records details that a user completes on a USERFORM and puts the into 'sheet 2' on a table.

My User form consists of text boxes, check boxes and an option button.

Everything works fine however there is something very annoying occurring and I can't find a solution.

If textbox1 is left blank and the check boxes are completed this data is logged on sheet 2, fine (lets call this Data Cap 1) . But when you create a new entry, if textbox1 has info keyed in, the entry (Which should be data Cap 2 on the next row down) populates the same row as Data Cap1.

Can anyone help me. Happy to provide code etc.. just not sure which part to send over.
 
Usually, you should start a new thread for a new problem, but I'll go ahead and give you the code to do what you're wanting. So if you have a second button in your userform to delete the last entry, paste this code in the click sub.

Code:
Dim ws As Worksheet
Dim lRow As Long
Set ws = Thisworkbook.Sheets(2)
lRow = ws.Range("J" & Rows.Count).End(xlUp).Row
Msg1 = msgbox("You are about to delete the last entry. Do you want to continue?" & vbNewLine & "Click yes to continue, or no to cancel.", vbYesNo)
If Msg1 = vbNo Then Exit Sub
ws.Range("A" & lRow).entirerow.delete
End Sub

I typed this on my phone, so try it out and let me know if it works ok.

Hi there,

This does work however ideally I'd like it keep rows 1 & 2 so it's only able to delete row 3 downwards if possible?
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I won't be able to work on it till later. If nobody else helps you, I'll make sure to update the code when I get back on.
 
Upvote 0
You're a hero. Thank you.

Add this "If" statement. This will keep from deleting rows 1 and 2.
Code:
Dim ws As Worksheet
Dim lRow As Long
Set ws = Thisworkbook.Sheets(2)
lRow = ws.Range("J" & Rows.Count).End(xlUp).Row
Msg1 = msgbox("You are about to delete the last entry. Do you want to continue?" & vbNewLine & "Click yes to continue, or no to cancel.", vbYesNo)
If Msg1 = vbNo Then Exit Sub
If lRow >= 3 Then ws.Range("A" & lRow).entirerow.delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,441
Messages
6,136,652
Members
450,022
Latest member
Joel1122331

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