Reputation: 741
I need to write a macro that apply NumberFormat = "General"
to all cells in a spreadsheet.
This is what I have
Sub set_general_format()
Select Case _
MsgBox("Do you want to apply generic to all cells?" _
& "Save before?", vbYesNoCancel, _
"Or just change to numeric?")
Case Is = vbYes
ThisWorkbook.Save
Case Is = vbCancel
Exit Sub
End Select
Sheets(1).Select
For i = 1 To Sheets.Count
Sheets(i).Select
Cells.Select
Selection.NumberFormat = "General"
Application.CutCopyMode = False
Next i
End Sub
Can someone help me to improve this code?
Upvotes: 0
Views: 325
Reputation:
Replace all of:
Sheets(1).Select
For i = 1 To Sheets.Count
Sheets(i).Select
Cells.Select
Selection.NumberFormat = "General"
Application.CutCopyMode = False
Next i
With:
For Each Sheet In ThisWorkbook.Sheets
Sheet.Cells.NumberFormat = "General"
Next
Upvotes: 0
Reputation: 243
You can combine the three lines:
Sheets(i).Select
Cells.Select
Selection.NumberFormat = "General"
in one line as follows:
Sheets(i).Cells.NumberFormat = "General"
Upvotes: 1