ho creato questa semplice macro excel per correggere un documento Excel che spesso arriva compilato male:
- Codice: Seleziona tutto
' --- INIZIO ---
Sub Pulizia()
' POSIZIONE CURSORE ALLA PRIMA CELLA
Range("A1").Select
' DISATTIVA AGGIORNAMENTO FINESTRA
Application.ScreenUpdating = False
' RIMUOVE IPERLINK EMAIL
Range("R6:S6").Select
Selection.Hyperlinks.Delete
' IMPOSTA CARATTERE ARIAL 9
Cells.Select
Selection.Font.Name = Arial
Selection.Font.Size = 9
' MAIUSCOLIZZA DATI INSERITI E IMPOSTA A CAPO AUTOMATICO
' --> !!! la riga che segue è quella in cui la macro si blocca !!! < ---
Range("A3:S4,A6:S6,A8:Q8,B10:Q10,B12:Q12,M13:Q13,R7:S10,N15:S15,M16:S16,B19:M21,N19:S19,N21:O21,P21:R22,O23:S23,P24,B27:S27,B28,B29:O29,P28:S30,E31:M31,P32,B35:S35,B36,B37:O37,P36:S38,E39").Select
For Each x In Selection
x.Value = UCase(x.Value)
x.WrapText = True
Next
Range("P40,B66:P67,S66:S67,B69:P69,S69:S70,B72:S73,B75:S76,B77,A78:L78,Q78:S78,B15:L16").Select
For Each x In Selection
x.Value = UCase(x.Value)
x.WrapText = True
Next
' CORREGGE CARATTERE DATI INSERITI
Range("A3:S4,A6:S6,A8:Q8,B10:Q10,B12:Q12,M13:Q13,R7:S10,N15:S15,M16:S16,B19:M21,N19:S19,N21:O21,P21:R22,O23:S23,P24,B27:S27,B28,B29:O29,P28:S30,E31:M31,P32,B35:S35,B36,B37:O37,P36:S38,E39,P40,B66:P67,S66:S67,B69:P69,S69:S70,B72:S73,B75:S76,B77,A78:L78,Q78:S78").Select
With Selection
.Font.Bold = False
.Font.Italic = False
.Font.Strikethrough = False
.Font.Superscript = False
.Font.Subscript = False
.Font.OutlineFont = False
.Font.Shadow = False
.Font.Underline = xlUnderlineStyleNone
.Font.ColorIndex = xlAutomatic
.Font.TintAndShade = 0
.Font.ThemeFont = xlThemeFontNone
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Range("B15:L16").Select
With Selection
.Font.Bold = False
.Font.Italic = False
.Font.Strikethrough = False
.Font.Superscript = False
.Font.Subscript = False
.Font.OutlineFont = False
.Font.Shadow = False
.Font.Underline = xlUnderlineStyleNone
.Font.ColorIndex = xlAutomatic
.Font.TintAndShade = 0
.Font.ThemeFont = xlThemeFontNone
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
' RIPRISTINA COLORE RIEMPIMENTO IN BIANCO
Range("A3:S4,A6:S6,A8:Q8,A9,B10:Q10,R7:S10,A11:A64,B12:Q12,M13:Q13,B15:S17,B19:S19,B20,B21:O21,O22,P21:R22,S21,B23:S25,B27:S27,B28,B29:O29,O30,P28:S30,B31:B32,E31:S32,B33:S33,B35:S35,B36,B37:O37,O38,P36:S38,B39:B40,E39:S40,B41:S41,B43:S43").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("B44,B45:O45,O46,P44:S46,B47:B48,E47:S48,B49:S49,B51:S51,B52,B53:O53,O54,P52:S54,B55:B56,E55:S56,B57:S57,B59:S59,B60,B61:O61,O62,P60:S62,B63:B64,E63:S64,B65:S65,B66:Q67,R66,S66:S67,B69:Q70,R69,S69:S70,B72:S63,B75:S76,B77:L77,A78:S78").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
'IMPOSTA DESCRIZIONE ATTIVITA' e UNITA' ORGANIZZATIVA IN ROSSO
Range("M3:Q3,O6").Select
With Selection
.Font.Color = -16776961
End With
'IMPOSTA DESCRIZIONE ATTIVITA' IN GRASSETTO
Range("M3:Q3").Select
With Selection
.Font.Bold = True
End With
' IMPOSTA ZOOM AL 89%
ActiveWindow.Zoom = 89
' RIMUOVE VISTA GRIGLIA
ActiveWindow.DisplayGridlines = False
' NASCONDE RIGA 81
Rows("81:81").RowHeight = 0
' INSERISCE BORDI MANCANTI X TUTTI I LATI
Range("A5:Q6,R6:S6,A7,O9:Q10,B11:Q13,N19,R21:S23,N23,N31:N32,N40,N48,N56").Select
With Selection
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeRight).Weight = xlMedium
.Borders(xlInsideVertical).Weight = xlMedium
.Borders(xlInsideHorizontal).Weight = xlMedium
End With
' INSERISCE BORDI SUPERIORI MANCANTI
Range("P24").Select
With Selection
.Borders(xlEdgeTop).Weight = xlMedium
End With
' INSERISCE BORDI INFERIORI MANCANTI
Range("R5:S5,M9:N9,R14,P24,R24,N31,P32,R32,N39,P40,R40,N47,N55,N63,B77:P77").Select
With Selection
.Borders(xlEdgeBottom).Weight = xlMedium
End With
' ATTIVA AGGIORNAMENTO FINESTRA
Application.ScreenUpdating = True
' POSIZIONA CURSORE IN CAMPO B12
Range("B12").Select
End Sub
'--- FINE ---
purtroppo al primo avvio mi segnala:
---
Errore di run-time '1004':
Metodo 'Range' dell'oggetto '_Global' non riuscito
---
rilanciando la macro dalla seconda volta in poi tutto funziona regolarmente.
Qualcuno mi sa indicare in cosa sbaglio?
premetto che non ho molta esperienza in programmazione.
Grazie in ogni caso.
Moderazione: sposto in "Applicazioni Office"