Hi, I've tried various ways but nothing seems to work for the code I have.
The below code allows me to add data to a new row from UserForm1.
I need assistance with changing the code so that I can select the row which will populate the UserForm and allow me to amend/update the data.
The code below is for userForm1, I need it to apply to UserForm3 if possible?
The below code allows me to add data to a new row from UserForm1.
I need assistance with changing the code so that I can select the row which will populate the UserForm and allow me to amend/update the data.
The code below is for userForm1, I need it to apply to UserForm3 if possible?
VBA Code:
Option Explicit
Dim ary1 As Variant, ary2 As Variant, ary3 As Variant, aryRISK As Variant
Dim tbl1 As ListObject, tbl2 As ListObject, tbl3 As ListObject, tblRISK As ListObject
Dim ws1 As Worksheet, ws2 As Worksheet
Dim newrow As ListRow
Dim reins As String
Dim msgValue As VbMsgBoxResult
Dim X As Long
Private Sub UserForm_Initialize()
Set ws1 = LIVE
Set tblRISK = ws1.ListObjects("FAC_RISKS")
Set ws2 = Sheet2
Set tbl1 = ws2.ListObjects("Table1")
Set tbl2 = ws2.ListObjects("Table2")
Set tbl3 = ws2.ListObjects("Table3")
With tbl1
If .ListRows.Count = 1 Then
Me.cedent.AddItem .DataBodyRange(1)
Else
ary1 = .DataBodyRange
Me.cedent.List = ary1
End If
End With
With tbl2
If .ListRows.Count = 1 Then
Me.status.AddItem .DataBodyRange(1)
Else
ary1 = .DataBodyRange
Me.status.List = ary1
End If
End With
With tbl3
If .ListRows.Count = 1 Then
Me.reinsurers.AddItem .DataBodyRange(1)
Else
ary1 = .DataBodyRange
Me.reinsurers.List = ary1
End If
End With
End Sub
Private Sub ADDCommandButton1_Click()
msgValue = MsgBox("Save & Add This Risk Now?", vbYesNo + vbInformation, "Confirmation")
If msgValue = vbNo Then Exit Sub
reins = ""
With Me.reinsurers
For X = 0 To .ListCount - 1
If .Selected(X) = True Then
reins = reins & .List(X) & vbCrLf
End If
Next X
End With
Set newrow = tblRISK.ListRows.Add
With newrow
.Range(2) = Me.reference.Value
.Range(3) = Me.insured.Value
.Range(4) = CDate(Me.startdate.Value)
.Range(5) = CDate(Me.enddate.Value)
.Range(6) = Me.share.Value / 100
.Range(7) = reins
.Range(8) = Me.brokerage.Value
.Range(9) = Me.excess.Value
.Range(10) = Me.cedent.Value
End With
Unload Me
UserForm1.Show
End Sub