Hi
In my userform i add data to the sheet as the code below:
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
If ws.Cells(1, 1) <> "" Then iRow = iRow + 1
I = Val(ComboBox2.Tag)
ws.Cells(iRow, 1) = ComboBox3.Value
ws.Cells(iRow, 6) = TextBox2.Value
ws.Cells(iRow, 3) = TextBox3.Value
ws.Cells(iRow, 2) = ComboBox4.Value
ws.Cells(iRow, 4) = ComboBox2.List(I, 0)
ws.Cells(iRow, 5) = ComboBox2.List(I, 1)
Is it possible to add a formula that merge the cell in column A (iROW1) and B(iROW2) to Column G (iROW7)
something like below ?
ws.Cells(iRow, 7) = Formula "=A&B"
All Code
Private Sub CommandButton1_Click()
Dim ws As Worksheet, txtb As Control
Dim aCell As Range, iRow As Integer
If Len(Trim(ComboBox2.Value)) = 0 Then
MsgBox "Ange Kontonummer"
ComboBox2.SetFocus
Exit Sub
End If
If Len(Trim(ComboBox3.Value)) = 0 Then
MsgBox "Ange År"
ComboBox3.SetFocus
Exit Sub
End If
If Len(Trim(ComboBox4.Value)) = 0 Then
MsgBox "Ange Månad"
ComboBox4.SetFocus
Exit Sub
End If
If Len(Trim(TextBox2.Value)) = 0 Then
MsgBox "Ange Beskrivning"
TextBox2.SetFocus
Exit Sub
End If
Set ws = Sheets(ComboBox1.Text)
If Not aCell Is Nothing Then
MsgBox "Account Already Exists"
Else
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
If ws.Cells(1, 1) <> "" Then iRow = iRow + 1
I = Val(ComboBox2.Tag)
ws.Cells(iRow, 1) = ComboBox3.Value
ws.Cells(iRow, 6) = TextBox2.Value
ws.Cells(iRow, 3) = TextBox3.Value
ws.Cells(iRow, 2) = ComboBox4.Value
ws.Cells(iRow, 4) = ComboBox2.List(I, 0)
ws.Cells(iRow, 5) = ComboBox2.List(I, 1)
End If
'~~> Clear All textboxes
For Each txtb In Me.Controls
If TypeName(txtb) = "TextBox" Then
txtb.Text = ""
End If
Next
Call ComboBox1_Change
End Sub
Best Regards
Petter
Bookmarks