Trubles with setting cell styles

PG_Develop

New Member
Joined
May 12, 2017
Messages
7
Hello, colleagues

I have written a macro, which resetting the cell style to each cell (some of the style features broke in my workbook, so I have to set them again). But it returns an error 450 "Wrong number of arguments or invalid property assignment" on the line, which I painted in red in the code bellow. Please advise me on what I am doing wrong..

Sub ReSetStyle()
Application.ScreenUpdating = False

Dim Cell As Range
Dim PrevColorIndex As Integer
Dim CellStyleName As String
Dim ws As Worksheet
Dim efkoef As Long
Dim colkoef As Long
Dim Style As Long

efkoef = 0
colkoef = 0

For Each ws In ActiveWorkbook.Worksheets
For Each Cell In ws.UsedRange.Cells
PrevColorIndex = Cell.Interior.ColorIndex
CellStyleName = Cell.Style
Cell.Style = CellStyleName

If Cell.Interior.ColorIndex <> PrevColorIndex Then
Cell.Interior.ColorIndex = PrevColorIndex
colkoef = colkoef + 1
End If
efkoef = efkoef + 1
Next Cell
Next ws

MsgBox "Formatting completed successfully" & vbNewLine & "Formatted cells: " & efkoef & vbNewLine & "Painted cells " & colkoef

Application.ScreenUpdating = True
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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