How to add comments in excel cells by VBA

 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 Worksheet
Set ws = Sheets("Sheet1")
'Define last row
Dim i As Long
i = ws.Range("B" & Rows.Count).End(xlUp).Row + 1
'Now to transfering data to worksheet
ws.Cells(i, 1) = Me.TextBox1
ws.Cells(i, 2) = Me.TextBox2
ws.Cells(i, 3) = Me.TextBox3
ws.Cells(i, 4) = Me.TextBox4

'to add comment
ws.Cells(i, 4).AddComment
ws.Cells(i, 4).Comment.Text Text:= "Your Text" & Chr(10) & Me.TextBox5

MsgBox "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