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

wsnyder

Board Regular
Joined
Sep 23, 2018
Messages
224
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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,223,937
Messages
6,175,510
Members
452,650
Latest member
Tinfish

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