I want to Paste values from an Excel Userform to a sheet. The values can be pasted into diffrent sheets depending on what you put inside of the Userform.
I have come this far:
Private Sub Lagginarenda_Click()
Sheets("KategoriComboBox").Range("B2").Value = TextBoxFragestallare.Value
End Sub
The KategoriComboBox is a Userform Dropdown list in which you can choose a name in. The same values that contains in that list have a similar Excel sheet.
The TextBoxFragestallare is a TextBox in which you can write in a value. This Value I want to paste inside of Cell B2 in a sheet that you also choose inside of the userform.
The Code wont work because it says "Index out of bound- Runtime error '9'"
I have managed to come this far:
Private Sub Lagginarende_Click()
Dim emptyRow As Long
'Aktiverar sheet
Sheets("Byggkonstruktion").Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Överför information
Cells(emptyRow, 1).Value = TextBoxLopnummer.Value
Cells(emptyRow, 2).Value = TextBoxFragestallare.Value
Cells(emptyRow, 3).Value = TextBoxMottagare.Value
Cells(emptyRow, 4).Value = TextBoxDatum.Value
Cells(emptyRow, 5).Value = TextBoxFraga.Value
Cells(emptyRow, 8).Value = TextBoxSvar.Value
If KanBesvaraFraganJa.Value = True Then Cells(emptyRow, 6).Value = KanBesvaraFraganJa.Caption Else Cells(emptyRow, 6).Value = KanBesvaraFraganNej.Caption
Unload Me
End Sub
The only issue I have now is how can I instead of using Sheets("Byggkonstruktion").Activate use the value in a drop-down list that is in the userform?
Best Answer
If I understand your question correctly, you want to let the user select a certain sheet name through a dropdown control and then paste the text they entered in this sheet in cell 'B2'.
So your setup might look something like this:
Here is how you can achieve this: (Suppose you have a ComboBox named cbxSheet, a TextBox named txbText and a CommandButton named btnCopyTextToSelectedSheet in a UserForm)
I uploaded the sample here: https://dl.dropboxusercontent.com/u/40951326/SheetSelectionExample.xlsm
Hope this gives you an idea on how to achieve what you want!