What I currently have working (it's a working progress still to be tweaked) is a Userform for inputting data into relevant rows (inputform).
What I now need and have almost got working is another Userform for adding in some additional information and preferably overwriting any existing data (updateform).
I'm very new to VBA and have been doing my best to get my head around it but can't say I completely understand all the terms, I work with taking existing code I have found elsewhere and editing it to best suit my needs. This means a lot of fiddling to try see exactly what each line of code is doing. With my current task I've about reached my limit and am now well and truly stuck on how to fix this issue. In short, there may be a lot of irrelevant/incorrect lines of code that I haven't realised are irrelevant/incorrect.
So, to the issue in hand.
I will have lots of unique contract numbers (column A) that I will be using to bring up the details in the update form.
I have the client name (column D) which is currently serving as a check to make sure I have brought up the correct contract.
Then I have 7 more boxes to be filled out with the new data that I want added to existing rows (Columns AG,AM,AN,AO,AU,AV,AW)
I have a piece of code that I thought should work but it just adds the data to a new row and I can't seem to figure out why it is doing this or how to get it to instead write in the existing rows. (Update Button)
Private Sub cmbUpdate_Click()
Dim contract As String, client As String, setup As String, captm As String, inttm As String, arrtm As String, misspa As String, retpf As String, dpic As String
contract = txtContractNumber.Text
Cells(currentrow, 1).Value = contract
client = txtClient.Text
Cells(currentrow, 4).Value = client
setup = cbxSetUpFeePaid.Text
Cells(currentrow, 33).Value = setup
captm = txtCapitalThisMonth.Text
Cells(currentrow, 39).Value = captm
inttm = txtInterestThisMonth.Text
Cells(currentrow, 40).Value = inttm
arrtm = txtArrearsThisMonth.Text
Cells(currentrow, 41).Value = arrtm
misspa = txtMissedPaymentAmount.Text
Cells(currentrow, 47).Value = misspa
retpf = txtReturnedPaymentFee.Text
Cells(currentrow, 48).Value = retpf
dpic = txtDelayedPaymentInterestCharge.Text
Cells(currentrow, 49).Value = dpic
End Sub
The only thing that I can think of that would be causing this issue (if it's not part of the above code) is the piece of code that brings up the information to begin with. (Find Button)
Private Sub cmbFind_Click()
Dim lastrow
Dim myContractNumber As String
lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
myContractNumber = txtContractNumber.Text
For currentrow = 2 To lastrow
If Cells(currentrow, 1).Text = myContractNumber Then
txtContractNumber.Text = Cells(currentrow, 1).Text
txtClient.Text = Cells(currentrow, 4).Text
End If
Next currentrow
txtContractNumber.SetFocus
End Sub
Please let me know if I've missed out any relevant data!
Bookmarks