Copying any Combobox1 value to the first blank row of another Sheet when that value in Combobox1 is clicked

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
884
Office Version
  1. 365
Platform
  1. Windows
As stated in the title. I just want to copy any item I click on in the Combobox1 dropdown list on Userform1 to the first blank row of Sheet2 the moment the item in Combobox1 is clicked. Seems simple enough.
Both Sheets 1 and 2 have just two columns of data; Headers: Col A = Item, Col B = Amount. 'Combobox1 Rowsource = =Sheet1!A2:B20
Below is what I have so far:
Code:
Private Sub ComboBox1_Click()
Dim x
x = Me.ComboBox1.Column(0) ' col A is the Item  'Me = Userform1
Y = Me.ComboBox1.Column(1) 'col B is the Amount ' Both x and Y are row values in Sheet1, the values to copy
Dim LastRow As Long, cellData As Variant
        With Worksheets("Sheet2")  'the sheet to be copied to.  Both values in cols A and B of Sheet1 must be copied.
            LastRow = .Range("A" & .Rows.count).End(xlUp).Row + 1
            .Range("A" & CStr(LastRow)).value = x 'cellData  ' this only copies the value in col A 
        End With
End Sub
I may have left something out that's not copying the value in col B to Sheet2.
Thanks for anyone's help. I know this is something simple I'm missing.
cr.






[/code]
The problem with the code above is that it only copies the value in col A, - it doesn't copy the value amount on that same row to col B
of Sheet2.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try this:

VBA Code:
Private Sub ComboBox1_Click()
  Dim LastRow As Long
  With Worksheets("Sheet2")  'the sheet to be copied to.  Both values in cols A and B of Sheet1 must be copied.
    LastRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1
    .Range("A" & LastRow).Value = Me.ComboBox1.List(ComboBox1.ListIndex, 0) 'cellData  ' this only copies the value in col A
    .Range("B" & LastRow).Value = Me.ComboBox1.List(ComboBox1.ListIndex, 1)
  End With
End Sub
 
Upvote 0
Hi DanteAmor - well, it works great. Something so simple as 1 additional line of code.
Many thanks as always for all your help.
cr :)
 
Upvote 1

Forum statistics

Threads
1,214,815
Messages
6,121,715
Members
449,049
Latest member
THMarana

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