VBA
Marc
please see attached vba code I am using for copying text which is written in 2 text boxes to another worksheet ( sheet 2 ). It is working fine.
For example I write ( Marc ) in the first text box ( txt content ) and ( Marc II ) in the second (txtcap) it should transfer those into the sheet 2. Then I write again the same text into the boxes and click the Submit button ( Combo Box ) it should write the text exactly below the text before in sheet2.
Now the problem. If I format the Cells like " Center " it seems that the text is not going to be written in those cells. It is going below that. Could it be that the "rngusedrange" command also takes formatted cells as used?
Code:
Private Sub CommandButton1_Click()
Dim wksworksheet As Worksheet
Dim rngusedRange As Range
Dim strErrormessage As String
Dim lngRows As Long
strErrormessage = ""
If txtcontent = "" Then strErrormessage = strErrormessage & _
" Error 1: Please fill in field 1!" _
& Chr(10) & Chr(13)
If strErrormessage = "" Then
Set wksworksheet = ThisWorkbook.Worksheets("sheet2")
Set rngusedRange = wksworksheet.UsedRange
lngRows = rngusedRange.Rows.Count
wksworksheet.Cells(lngRows + 1, 2).Value = txtcontent.Text
wksworksheet.Cells(lngRows + 1, 3).Value = TxtCap.Text
Else
MsgBox strErrormessage
End If
End Sub
Any help is highly appreciated!
Thanks a lot and BR
Marc