Today we will discuss How to add comment in excel cells by VBA when we add data into excel worksheet through vba method
Data entry by userform and add comment into excel cells
Full VBA codes are given below
Double click on Add command button and write the below codes
Private Sub CommandButton1_Click()Dim ws As WorksheetSet ws = Sheets("Sheet1")'Define last rowDim i As Longi = ws.Range("B" & Rows.Count).End(xlUp).Row + 1'Now to transfering data to worksheetws.Cells(i, 1) = Me.TextBox1ws.Cells(i, 2) = Me.TextBox2ws.Cells(i, 3) = Me.TextBox3ws.Cells(i, 4) = Me.TextBox4'to add commentws.Cells(i, 4).AddCommentws.Cells(i, 4).Comment.Text Text:= "Your Text" & Chr(10) & Me.TextBox5MsgBox "Data Transfer Successfully !"Me.TextBox1 = ""Me.TextBox2 = ""Me.TextBox3 = ""Me.TextBox4 = ""Me.TextBox5 = ""End Sub
To add comment into the cells follow the below code where you need to define i as long which help you to add data as comment into a particular cell and the function Chr(10) which is used to create separate line.
'to add comment
ws.Cells(i, 4).AddComment
ws.Cells(i, 4).Comment.Text Text:= "Your Text" & Chr(10) & Me.TextBox5
For Support and Feedback
Please contact through contact form and subsribe my YouTube channel
No comments:
Post a Comment