Cell Style Run-time error '450': Wrong number of arguments or invalid property assignment

wsnyder

Board Regular
Joined
Sep 23, 2018
Messages
223
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am trying to apply a Hyperlink Cell Style to a Range (single cell in this case) but I keep receiving an error message:
Run-time error '450': Wrong number of arguments or invalid property assignment

Not sure what I'm doing wrong, seem correct and the style definitely exists in the workbook
Thoughts?

Thanks,
-w
VBA Code:
    'Objects
      dim myrangeobject as range

        'Sheet protection
        'If the worksheet is protected, unprotect it, else do nothing
          bProtectionStatus = GetProtectionStatus(ws:=ws)
          If bProtectionStatus Then
              ws.Unprotect Password:="stuff"
          End If
 
    'Create range
       With ws
         Set myrangeobject = .Range(.Cells(8, 15), .Cells(8, 15))
       End with

    'Unlock cells
        myrangeobject .Locked = False

   'Test range
      Debug.Print myrangeobject .Address <<-- This returns the correct address

    'Apply cell styles
        myrangeobject.style = "Hyperlink"

I wrote a quick test in a new workbook in a new module and it works as expected so I'm not sure why my code in my other workbook does not work?
Test:
Code:
Option Explicit

Sub foo()

    Dim wb As Workbook
    Dim ws As Worksheet
    Dim rng As Range
  
    Set wb = ThisWorkbook
    Set ws = wb.Worksheets(1)
    Set rng = ws.Range("A1")
  
    rng.Style = "Hyperlink"
  
    Set rng = Nothing
    Set ws = Nothing
    Set wb = Nothing
  
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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