Invalid Procedue call or Argument

Firasath

Board Regular
Joined
Feb 20, 2011
Messages
134
Office Version
  1. 365
Hi,

Can somebody please advise why I am getting Run Time Error 5 while running below simple code. When I run the same code with a single cell it works fine but not with Range.

Sub test()

Range("A24:T24").AddComment ("Test")

End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You can Use
VBA Code:
Sub test()Dim j as long
For j=1 to 20
Cells(24,  j).AddComment ("Test")
Next j
End Sub
 
Upvote 0
Solution
Thank you very much maabadi.

I would like to know the reason for that code not working. Does the AddComment doesn't work with range of cells?

Actually I am trying to build a code to add comments to KPIs based on the formula (hlookup) result. It is a big database with number of different KPIs. I want to use name references instead of cell references to avoid any manual work on codes on inserting any new rows. I will attach xl2bb sheet below for your kind reference. Appreciate if you can support on me on this as I am struggling or long time now.

Comments to be added to SLA Adherence KPI. Target row is the target result of hlookup which needs to be updated in SLA Adherence columns' comments.

Book12.xlsm
H
12
Sheet1



First time trying to attach xl2bb. Not sure how it would work.
 
Upvote 0
First select the range you want upload then Click on MiniSheet and accept popup
Then Paste Here to we see what you want.
 
Upvote 0
Please find below.

Book12.xlsm
ABCDEFGHIJKLMNOPQRSTU
1Jun-20Jul-20Aug-20Sep-20Oct-20Nov-20Dec-20Jan-21Feb-21Mar-21Apr-21May-21Jun-21Jul-21Aug-21Sep-21Oct-21Nov-21Dec-21
2Target90%90%95%95%95%97%97%97%97%97%97%97%97%97%97%97%97%97%97%
3SLA Adherence88.0%90.0%93.0%94.0%95.0%97.0%96.0%88.0%
8
9
10
11MonthJun-20Aug-20Nov-20
12Target90%95%97%
13
14
Sheet1
Cell Formulas
RangeFormula
B2:T2B2=HLOOKUP(B1,$L$11:$T$12,2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B3:T3Expression=B3<HLOOKUP(B1,$L$11:$S$12,2)textNO
 
Upvote 0
What about this for row 3:
VBA Code:
Sub test()
Dim j as long
For j=1 to 20
if Cells(3, j).value < Cells(2, j).value then
Cells(3,  j).AddComment ("Test")
End if
Next j
End Sub
 
Upvote 0
I am trying below code, can you help me why I am getting error "Application-defined or object-defined error".

SQL:
Sub AddComment1()

Dim i As Integer, rng As range, StartCell As range, Cmt As Variant, dt As range

Set rng = range("b3")
Set StartCell = rng
Set dt = range("b1")

'On Error Resume Next

    For i = 1 To 10
    
                Cmt = Application.WorksheetFunction.HLookup(dt.Offset(0, i - 1), range("$K$11:$N$12"), 2)
                
                rng.Offset(0, i - 1).AddComment Cmt
              
    Next i
'On Error GoTo 0

StartCell.Select
  
End Sub
 
Upvote 0
Yu don't need add $ sign at VBA window, at usual way, remove them.
 
Upvote 0
Thanks. Removed it and it worked by specifying a text as a comment but when I am trying to put "Cmt Variable" to update the corresponding hlookup result in cell, it is still giving same error. What could be the reason for it.

Error: Application-defined or object-defined error

SQL:
Sub AddComment1()

Dim i As Integer, rng As range, dt As range, Cmt As Variant,

Set rng = range("b3")
Set dt = range("b1")

'On Error Resume Next

    For i = 1 To 10
    
                Cmt = Application.WorksheetFunction.HLookup(dt.Offset(0, i - 1), range("K11:N12"), 2)
                
                rng.Offset(0, i - 1).AddComment [B]Cmt[/B]
              
    Next i
'On Error GoTo 0

rng.Select
  
End Sub
 
Upvote 0
What means Cmt Variable?
Is it Range? Text? Values?
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,134
Members
449,206
Latest member
burgsrus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top