Userform combobox copy selection and paste

tynawg

New Member
Joined
Oct 11, 2019
Messages
42
Hi,
Below is a pic of the SOR Validation userform for explanation.
Code is below that.
I am breaking the issue into small parts.
I would like help with the following. Lets say, as is the case in this picture, a user has selected Carpenter_Joiner in first dropdown then CABM03 in the second. This the displays the data from the excel file to the right from columns C, D and E in the text box.
What I want to do is set one of the command buttons to copy the row, which would be row 7 in this example, ending at column F. So it would copy row 7 data only from column A to F. The copied data will then be pasted to a yet to be defined location, but it will be part of a worksheet. That part forms part of the larger project and I only want to tackle bite sized bits with each post. I will post a new question once this part is solved.
Thank you in advance for any help.
Regards,
Wayne

1576804504249.png







VBA Code:
Private Sub workbook_open()
    GMSORs.Show
End Sub
'Private Sub UserForm_Initialize()
    
'    Me.ComboBox1.RowSource = ""
'    Me.ComboBox2.RowSource = ""
'    Me.TextBox1.MultiLine = True
'    Me.TextBox1.BackColor = "&H80000004"
    
    'This code pulls the trade names
'    With Sheets("GMSOR's")
'        Me.ComboBox1.Value = ActiveCell.Offset(0, -1).Value
'        Me.ComboBox2.Value = ActiveCell.Value
'        ActiveCell.Offset(0, 1).Select
'    End With

'End Sub
Private Sub UserForm_Initialize()
    
    Me.ComboBox1.RowSource = ""
    Me.ComboBox2.RowSource = ""
    Me.TextBox1.MultiLine = True
    Me.TextBox1.BackColor = "&H80000004"
    
    'This code pulls the trade names
    With Sheets("GMSOR's")
    Me.ComboBox1.List = .Range("K2", .Cells(.Rows.Count, "K").End(xlUp)).Value
    ActiveCell.Offset(0, 1).Select
    End With

End Sub

Private Sub ComboBox2_Enter()
Dim vList, i As Long

With Sheets("GMSOR's")
vList = .Range("A1:B" & .Cells(.Rows.Count, "A").End(xlUp).Row)
End With

Me.ComboBox2.Clear
    
    For i = LBound(vList) To UBound(vList)
    If UCase(vList(i, 1)) = UCase(Me.ComboBox1.Value) Then Me.ComboBox2.AddItem vList(i, 2)
    Next

End Sub


Private Sub ComboBox1_Change()
Me.ComboBox2.Clear
End Sub


Private Sub ComboBox2_Change()
Dim c As Range
Dim fm

TextBox1 = ""
With Sheets("GMSOR's")
fm = Application.Match(Me.ComboBox2, .Range("B1", .Cells(.Rows.Count, "B").End(xlUp)), 0)
    If IsNumeric(fm) Then
        For Each c In .Range("C" & fm & ":E" & fm)
            tx = tx & " - " & c
        Next
        TextBox1 = Right(tx, Len(tx) - 3)
    End If
 
End With
End Sub

Private Sub TextBox1_Enter()
Me.ComboBox2.SetFocus
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
For the CommandButton1.
Change the sheetX to the name of your sheet.

VBA Code:
Private Sub CommandButton1_Click()
  Dim sh As Worksheet, n As Variant
  Set sh = Sheets("SheetX")
  With sh.Range("A1:A" & sh.Range("A" & Rows.count).End(xlUp).Row)
    n = Evaluate("=MATCH(""" & ComboBox1.Value & "" & "|" & "" & ComboBox2.Value & """," & _
    .Address(external:=True) & "&""|""&" & .Offset(, 1).Address(external:=True) & ",0)")
  End With
  If IsError(n) Then
    MsgBox "Data does not exists"
  Else
    sh.Range("A" & n & ":F" & n).Copy
    MsgBox "Row to copy " & n
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,755
Members
448,989
Latest member
mariah3

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