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
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