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
 
It is a the result of hkookup formula. In destination table it is updated in percentage format, which would be number (Integer)
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
AND I think you should Dim it at Double because Percents has numbers after point.
 
Upvote 0
I even tried that. Can you please copy my excel sheet from above and try the code. I copied ot above. Appreciate your support.
 
Upvote 0
This worked If before don't has comments.
VBA Code:
Sub AddComment1()
Dim i As Integer, rng As Range, dt As Range, Cmt As String
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 Cmt
Next i
'On Error GoTo 0
rng.Select
End Sub
 
Upvote 0
Thank you very much brother, it worked. I tried all data types myself but it didn't work, maybe I made some other mistake. Thanks again :).
 
Upvote 0
Are you sure you don't have any comments at cells Before running this code with dim as string.
What about this:
VBA Code:
Sub AddComment1()
Dim i As Integer, rng As Range, dt As Range, Cmt As String
Set rng = Range("b3")
Set dt = Range("b1")
'On Error Resume Next
Range("B3:T3").ClearComments
For i = 1 To 10
   Cmt = Application.WorksheetFunction.HLookup(dt.Offset(0, i - 1), Range("K11:N12"), 2)
         rng.Offset(0, i - 1).AddComment Cmt
Next i
'On Error GoTo 0
rng.Select
End Sub
 
Upvote 0
Might be, I was trying many different ways at that time. So their might be comments at that time. Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,709
Members
449,093
Latest member
Mnur

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