Tom
Tom

Reputation: 65

How to paste a username into a cell?

I need to paste a text box content from Sheet1 into the last row of column "B" in Sheet9. I have no problem inserting the text box content (a string) from a text box in Sheet1 into the last row in Sheet9 column "B" by using the Enter key. However, I find it difficult to add the username to the last row in Column "C", adjacent to the last row in column "B" in Sheet9.

Here I am copying the text box content from Sheet1 to the last row in column "B" in Sheet9, and trying to put the username in the last row in column "C" in Sheet 9.

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    With Sheet9
        If KeyCode = 13 Then
            If TextBox1 <> vbNullString Then
                .Cells(.Rows.count, "B").End(xlUp)(2, 1) = TextBox1
                .Cells(.Rows.count, "C").End(xlUp)(2, 1)= Environ("username")
            End If
        End If
    End With
End Sub

Upvotes: 0

Views: 279

Answers (1)

Subodh Tiwari sktneer
Subodh Tiwari sktneer

Reputation: 9976

Since you want to insert the UserName in column C in the row which should be the first empty row in column B, all you need is to place the UserName in column C first and then insert the TextBox value in column B.

Please give this a try...

.Range("B" & Rows.Count).End(3)(2).Offset(0, 1) = Environ("UserName")
.Range("B" & Rows.Count).End(3)(2) = Textbox1

Upvotes: 2

Related Questions