PDA

View Full Version : insert comments from countif



jzamilpa3
05-21-2008, 05:10 AM
is it possible to insert a comment box and copy and paste wording into
it from 2 diffrent columns on another sheet. the thing is that i have
a countif in sheet3 columnB for the wording in columnA. the wording in
columnA is looked for in sheet2 that will provide how many times is
found. also there is wording next to the colunm the countif is looking
at and i need or wanted to insert a commentbox with the wording from
sheet2 into columnB of sheet3.


it should something like this
sheet 1
A B

bl a
asd a
fsd a
fs a
f b
sd c
fs c


sheet2
A B
a comment box of all a's
b comment box of all b's and so on
c
d

Bob Phillips
05-21-2008, 05:18 AM
Sub AddComments()
Dim LastRow As Long
Dim i As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRow

.Cells(i, "B").AddComment "Count of " & _
.Cells(i, "A").Value & " = " & _
Application.CountIf(Worksheets("Sheet2").Columns(2), .Cells(i, "A").Value)
Next i
End With
End Sub

jzamilpa3
05-21-2008, 05:39 AM
i get an error sayin out of range

Bob Phillips
05-21-2008, 05:44 AM
What is out of range?

jzamilpa3
05-21-2008, 06:13 AM
not sure. because its actually sheet 15 and 16. and i changed it so will be in range but thats what i get. the comments will go on sheet 16 columnB and and wording into commentsboxes from sheet15 columnA

DoLoop
05-21-2008, 06:19 AM
1. Be sure that sheet15 is active
2. Replace code of xld:


Application.CountIf(Worksheets("Sheet2").Columns(2), .Cells(i, "A").Value)


Into


Application.CountIf(Worksheets("Sheet16").Columns(2), .Cells(i, "A").Value)

jzamilpa3
05-21-2008, 06:41 AM
nope it shows up as out of range. could be that i already have a code in for sheet15 or maybe something else.

david000
05-22-2008, 07:32 PM
Sub AddComments()
Dim LastRow As Long
Dim i As Long

With ActiveSheet '< this is where the comments are going.

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRow

.Cells(i, "B").AddComment "Count of " & _
.Cells(i, "A").Value & " = " & _
Application.CountIf(Worksheets("Sheet2").Columns(2), .Cells(i, "A").Value) & _
Sheet1.Cells(i, "A").Text '<this is where the text is..e.g sheet2,3,4,etc.
Next i
End With
End Sub