Good Evening (or morning, depending on your geographic location).
I have only recently started with VBA, and have managed to piece together some code that will allow me to enter some data into a worksheet. Pretty standard stuff. I include the code below for the "submit" button.
Private Sub CommandButton1_Click()
Dim kRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Database")
With Worksheets("Database").Range("A1: A65535")
kRow = .Find(Me.ID.Value, LookIn:=xlValues).Row
End With
ws.Cells(kRow, 10) = Me.Soldprice.Value
ws.Cells(kRow, 11) = Me.SoldDate.Value
ws.Cells(kRow, 14) = Me.PaidBy.Value
ws.Cells(kRow, 12) = Me.BuyerName.Value
ws.Cells(kRow, 13) = Me.BuyerAddress.Value
ws.Cells(kRow, 14) = Me.BuyersAddress2.Value
ws.Cells(kRow, 15) = Me.BuyersAddress3.Value
ws.Cells(kRow, 16) = Me.BuyersAddressTown.Value
ws.Cells(kRow, 17) = Me.BuyersAddressCounty.Value
ws.Cells(kRow, 18) = Me.BuyersAddressPostCode.Value
ws.Cells(kRow, 19) = Me.BuyersTelephone.Value
ws.Cells(kRow, 20) = Me.BuyersEmail.Value
ws.Cells(kRow, 21) = "SOLD"
Dim k2Row As Long
Dim a2Row As Long
Dim b2Row As Long
Dim c2Row As Long
Dim d2Row As Long
Dim e2Row As Long
Dim f2Row As Long
Dim ws2 As Worksheet
Set ws2 = Worksheets("Sales Record")
'find first empty row in database
k2Row = ws2.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'copy the data to the database
ws2.Cells(k2Row, 1) = Me.ID.Value
ws2.Cells(k2Row, 2) = Me.Description.Value
ws2.Cells(k2Row, 3) = Me.Soldprice.Value
ws2.Cells(k2Row, 4) = Me.SoldDate.Value
ws2.Cells(k2Row, 14) = Me.PaidBy.Value
ws2.Cells(k2Row, 5) = Me.BuyerName.Value
ws2.Cells(k2Row, 6) = Me.BuyerAddress.Value
ws2.Cells(k2Row, 7) = Me.BuyersAddress2.Value
ws2.Cells(k2Row, 8) = Me.BuyersAddress3.Value
ws2.Cells(k2Row, 9) = Me.BuyersAddressTown.Value
ws2.Cells(k2Row, 10) = Me.BuyersAddressCounty.Value
ws2.Cells(k2Row, 11) = Me.BuyersAddressPostCode.Value
ws2.Cells(k2Row, 12) = Me.BuyersTelephone.Value
ws2.Cells(k2Row, 13) = Me.BuyersEmail.Value
ws2.Cells(k2Row, 15) = "SOLD"
I am looking to add another input to my form with "quantity", where the user can optionally insert a number. The same information will then be entered except for the "ID.Value" which will increase by one for each repetition. Is anyone able to advise a way of doing this, or telling me if I have made a bodge-job of the code above?
Regards
Ralph
Bookmarks