jamescooper
Well-known Member
- Joined
- Sep 8, 2014
- Messages
- 840
With the following code I am trying to take whatever is in Textbox6 in a userform - this is what is in column A of the spreadsheet. It finds this record in sheet and copies the array of texboxes/comboboxes to the sheet.
Any ideas how I can get it to work?
Thanks.
Any ideas how I can get it to work?
Thanks.
VBA Code:
Private Sub CommandButton1_Click()
Dim Msg As String
Dim Ans As Variant
Dim ary As Variant
Dim fn As Range
Msg = "Do you want overwrite record with ID " & TextBox6 & "?"
Ans = MsgBox(Msg, vbYesNo)
Select Case Ans
Case vbYes
ary = Array(TextBox6, TextBox1, TextBox9, TextBox5, TextBox13, TextBox15, TextBox13, ComboBox2, TextBox10, ComboBox1, ComboBox4, ComboBox16, TextBox21, ComboBox7, ComboBox9, ComboBox11, TextBox26, TextBox30, ComboBox8, TextBox31, ComboBox13, TextBox35, ComboBox10, TextBox32, TextBox33, TextBox34, ComboBox12, TextBox36, TextBox39, TextBox37, TextBox38, TextBox40, TextBox25, ComboBox3, ComboBox5, ComboBox6, ComboBox14, ComboBox15, 0, TextBox14, TextBox8, TextBox12, TextBox16)
With Edit
Set fn = Sheets("Data - Operations").Range("A:A").Find(.Range(ary(0)).Value, , xlValues, xlWhole)
If Not fn Is Nothing Then
For i = LBound(ary) To UBound(ary)
Sheets("Data - Operations").Cells(fn.Row, i + 1) = .Range(ary(i)).Value 'Starts in column 1 and goes accross based on array count
Next
End If
End With
End Sub