userform vba (credit control list)

apocalypticdon

New Member
Joined
Oct 4, 2014
Messages
2
im using the vba to make a userform to help father in law manage data in his personal business. he is still learning to use this stuff so im trying to make it as easy as possible for him. I have found the code:
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")

iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

If Trim(Me.TextBox_name.Value) = "" Then
Me.TextBox_name.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.TextBox_number.Value
ws.Cells(iRow, 2).Value = Me.TextBox_name.Value
ws.Cells(iRow, 3).Value = Me.TextBox_date.Value
ws.Cells(iRow, 4).Value = Me.TextBox_owed.Value
ws.Cells(iRow, 5).Value = Me.TextBox_paid.Value
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data
Me.TextBox_number.Value = ""
Me.TextBox_name.Value = ""
Me.TextBox_owed.Value = ""
Me.TextBox_paid.Value = ""
Me.TextBox_name.SetFocus
End Sub

that adds data to the next line and works good. but his list is what people owe him, so say a person pays that is like 2nd on list of 10 people, he will delete that person and there is a blank space in the list. the code will not see that space and will add it to the bottom. I would like to get the code to fill in any line open first to keep the list organized and compact. any help will be greatly apperciated
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
This returns the row of the 1st blank cell in column A

Code:
iRow = ws.Range("A:A").Find(What:="", SearchOrder:=xlByRows, SearchDirection:=xlNext, LookIn:=xlValues).Row
 
Upvote 0
This returns the row of the 1st blank cell in column A

Code:
iRow = ws.Range("A:A").Find(What:="", SearchOrder:=xlByRows, SearchDirection:=xlNext, LookIn:=xlValues).Row

thank you so much. I knew it couldn't be too hard but I been looking at several places and never seen how to do it. people always just find last row of table or whatever and never a empty spot. thanks for quick response
 
Upvote 0
You're welcome.

Alternatively; before adding the data, sort the rows (maybe based on the date column). That would remove blank rows in between. Then add the data to the bottom as before. That way, the rows are chronological. Just a thought.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

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