Pagina precedente | 1 | Pagina successiva
Vota | Stampa | Notifica email    
Autore

ciclo for /next

Ultimo Aggiornamento: 13/05/2016 23:44
Post: 1
Registrato il: 26/11/2006
Utente Junior
excel 2007
OFFLINE
11/05/2016 23:44

Buonasera,

è possibile semplificare la macro di cui sotto con il ciclo for/next?
chi mi aiuta? grazie [SM=x423017]

Range("A3").Select
Selection.EntireRow.Delete
Range("A5").Select
Selection.EntireRow.Delete
Range("A6").Select
Selection.EntireRow.Delete
Range("A8").Select
Selection.EntireRow.Delete
Range("A9").Select
Selection.EntireRow.Delete
Range("A11").Select
Selection.EntireRow.Delete
Range("A12").Select
Selection.EntireRow.Delete
Range("A14").Select
Selection.EntireRow.Delete
Range("A15").Select
Selection.EntireRow.Delete
Range("A17").Select
Selection.EntireRow.Delete
Range("A18").Select
Selection.EntireRow.Delete
Range("A20").Select
Selection.EntireRow.Delete
Range("A21").Select
Selection.EntireRow.Delete
Range("A23").Select
Selection.EntireRow.Delete
Range("A24").Select
Selection.EntireRow.Delete
Range("A26").Select
Selection.EntireRow.Delete
Range("A27").Select
Selection.EntireRow.Delete
Range("A29").Select
Selection.EntireRow.Delete
Range("A30").Select
Selection.EntireRow.Delete
Range("A32").Select
Selection.EntireRow.Delete
Range("A33").Select
Selection.EntireRow.Delete
Range("A35").Select
Selection.EntireRow.Delete
Range("A36").Select
Selection.EntireRow.Delete
Range("A38").Select
Selection.EntireRow.Delete
Range("A39").Select
Selection.EntireRow.Delete
Range("A41").Select
Selection.EntireRow.Delete
Range("A42").Select
Selection.EntireRow.Delete
Range("A44").Select
Selection.EntireRow.Delete
Range("A45").Select
Selection.EntireRow.Delete
Range("A47").Select
Selection.EntireRow.Delete
Range("A48").Select
Selection.EntireRow.Delete
Range("A50").Select
Selection.EntireRow.Delete
Range("A51").Select
Selection.EntireRow.Delete
Range("A53").Select
Selection.EntireRow.Delete
Range("A54").Select
Selection.EntireRow.Delete
Range("A56").Select
Selection.EntireRow.Delete
Range("A57").Select
Selection.EntireRow.Delete
Range("A59").Select
Selection.EntireRow.Delete
Range("A60").Select
Selection.EntireRow.Delete
Range("A62").Select
Selection.EntireRow.Delete
Range("A63").Select
Selection.EntireRow.Delete
Range("A65").Select
Selection.EntireRow.Delete
Range("A66").Select
Selection.EntireRow.Delete
Range("A68").Select
Selection.EntireRow.Delete
Range("A69").Select
Selection.EntireRow.Delete
Range("A71").Select
Selection.EntireRow.Delete
Range("A72").Select
Selection.EntireRow.Delete
Range("A74").Select
Selection.EntireRow.Delete
Range("A75").Select
Selection.EntireRow.Delete
Range("A77").Select
Selection.EntireRow.Delete
Range("A78").Select
Selection.EntireRow.Delete
Range("A80").Select
Selection.EntireRow.Delete
Range("A81").Select
Selection.EntireRow.Delete
Range("A83").Select
Selection.EntireRow.Delete
Range("A84").Select
Selection.EntireRow.Delete
Range("A85").Select
Selection.EntireRow.Delete
Range("A87").Select
Selection.EntireRow.Delete
Range("A88").Select
Selection.EntireRow.Delete
Range("A90").Select
Selection.EntireRow.Delete
Range("A91").Select
Selection.EntireRow.Delete
Range("A93").Select
Selection.EntireRow.Delete
Range("A94").Select
Selection.EntireRow.Delete
Range("A96").Select
Selection.EntireRow.Delete
Range("A97").Select
Selection.EntireRow.Delete
Range("A99").Select
Selection.EntireRow.Delete
Range("A100").Select
Selection.EntireRow.Delete
Post: 254
Registrato il: 16/08/2015
Città: CORDENONS
Età: 67
Utente Junior
Excel 2016-32bit Win11
OFFLINE
12/05/2016 00:34

E' un po' difficile automatizzare, c'è un cambio di passo in zona 81-86. Al massimo si può creare un elenco in array di celle fisse.
Avrebbe potuto funzionare qualcosa così:
    For x = 98 To 3 Step -3
        Range("A" & x).EntireRow.Delete
    Next x
[Modificato da rollis13 12/05/2016 00:35]

______________________________________________________________
C'è chi fa le COSE a CASO e chi fa CASO alle COSE (Ignoto)
Post: 1.878
Registrato il: 21/03/2008
Città: LOCATE VARESINO
Età: 76
Utente Veteran
2007 / 13
OFFLINE
12/05/2016 00:40

ciao

in base hai tuoi range() rilevati col generatore la sub() e' questa
PS ho fatto una prova con la tua sub()con righe da eliminare e con il risultato che ho ottenuto


Sub eliminaAlterna()
Dim i As Long
Dim conta As Long
conta = 1
For i = 3 To 100
If conta = 1 Then
Rows(i & ":" & i).Delete shift:=xlUp
conta = 0
i = i + 1
Else
Rows(i & ":" & i).Delete shift:=xlUp
conta = 1
End If
Next i
End Sub


Ciao da locate
excel 2007 / 13
Post: 622
Registrato il: 10/10/2013
Città: VICENZA
Età: 69
Utente Senior
365
OFFLINE
12/05/2016 01:47

Ciao
per me va così

Sub cicla()
Cells(3, 1).EntireRow.Delete
For i = 3 To 100 Step 3
Cells(i, 1).EntireRow.Delete
Next
End Sub

ma c'è un passaggio delle righe 83-84-85

che non coincide con lo step

non è che hai sbagliato a scrivere?

oppure doppio ciclo.
Post: 1
Registrato il: 26/11/2006
Utente Junior
excel 2007
OFFLINE
12/05/2016 15:28

Grazie a tutti, dei consigli.
In effetti alla fine macro ci sono degli errori perchè i step sono 2 e 1 alternati quindi verso gli 80 ci sono errori.
Post: 2
Registrato il: 26/11/2006
Utente Junior
excel 2007
OFFLINE
12/05/2016 22:28


la macro corretta è:

Range("A3").Select
Selection.EntireRow.Delete
Range("A5").Select
Selection.EntireRow.Delete
Range("A6").Select
Selection.EntireRow.Delete
Range("A8").Select
Selection.EntireRow.Delete
Range("A9").Select
Selection.EntireRow.Delete
Range("A11").Select
Selection.EntireRow.Delete
Range("A12").Select
Selection.EntireRow.Delete
Range("A14").Select
Selection.EntireRow.Delete
Range("A15").Select
Selection.EntireRow.Delete
Range("A17").Select
Selection.EntireRow.Delete
Range("A18").Select
Selection.EntireRow.Delete
Range("A20").Select
Selection.EntireRow.Delete
Range("A21").Select
Selection.EntireRow.Delete
Range("A23").Select
Selection.EntireRow.Delete
Range("A24").Select
Selection.EntireRow.Delete
Range("A26").Select
Selection.EntireRow.Delete
Range("A27").Select
Selection.EntireRow.Delete
Range("A29").Select
Selection.EntireRow.Delete
Range("A30").Select
Selection.EntireRow.Delete
Range("A32").Select
Selection.EntireRow.Delete
Range("A33").Select
Selection.EntireRow.Delete
Range("A35").Select
Selection.EntireRow.Delete
Range("A36").Select
Selection.EntireRow.Delete
Range("A38").Select
Selection.EntireRow.Delete
Range("A39").Select
Selection.EntireRow.Delete
Range("A41").Select
Selection.EntireRow.Delete
Range("A42").Select
Selection.EntireRow.Delete
Range("A44").Select
Selection.EntireRow.Delete
Range("A45").Select
Selection.EntireRow.Delete
Range("A47").Select
Selection.EntireRow.Delete
Range("A48").Select
Selection.EntireRow.Delete
Range("A50").Select
Selection.EntireRow.Delete
Range("A51").Select
Selection.EntireRow.Delete
Range("A53").Select
Selection.EntireRow.Delete
Range("A54").Select
Selection.EntireRow.Delete
Range("A56").Select
Selection.EntireRow.Delete
Range("A57").Select
Selection.EntireRow.Delete
Range("A59").Select
Selection.EntireRow.Delete
Range("A60").Select
Selection.EntireRow.Delete
Range("A62").Select
Selection.EntireRow.Delete
Range("A63").Select
Selection.EntireRow.Delete
Range("A65").Select
Selection.EntireRow.Delete
Range("A66").Select
Selection.EntireRow.Delete
Range("A68").Select
Selection.EntireRow.Delete
Range("A69").Select
Selection.EntireRow.Delete
Range("A71").Select
Selection.EntireRow.Delete
Range("A72").Select
Selection.EntireRow.Delete
Range("A74").Select
Selection.EntireRow.Delete
Range("A75").Select
Selection.EntireRow.Delete
Range("A77").Select
Selection.EntireRow.Delete
Range("A78").Select
Selection.EntireRow.Delete
Range("A80").Select
Selection.EntireRow.Delete
Range("A81").Select
Selection.EntireRow.Delete
Range("A83").Select
Selection.EntireRow.Delete
Range("A84").Select
Selection.EntireRow.Delete
Range("A86").Select
Selection.EntireRow.Delete
Range("A87").Select
Selection.EntireRow.Delete
Range("A89").Select
Selection.EntireRow.Delete
Range("A90").Select
Selection.EntireRow.Delete
Range("A92").Select
Selection.EntireRow.Delete
Range("A93").Select
Selection.EntireRow.Delete
Range("A95").Select
Selection.EntireRow.Delete
Range("A96").Select
Selection.EntireRow.Delete
Range("A98").Select
Selection.EntireRow.Delete
Range("A99").Select
Selection.EntireRow.Delete
Range("A101").Select
Selection.EntireRow.Delete


come si può ovviare a tante righe di comando?

Post: 1.880
Registrato il: 21/03/2008
Città: LOCATE VARESINO
Età: 76
Utente Veteran
2007 / 13
OFFLINE
13/05/2016 01:04

ciao

quindi deduco che la sub() che ti ho proposto non lai ne valutata ne provata
se provavi vedevi che questa corrispondeva alle tue esigenze

comunque basta che porti il ciclo for da 100 a 101 e otterrai lo stesso risultato della tua

la ripropongo corretta con un valore in piu'


Sub eliminaAlterna()
Dim i As Long
Dim conta As Long
conta = 1
For i = 3 To 101
If conta = 1 Then
Rows(i & ":" & i).Delete shift:=xlUp
conta = 0
i = i + 1
Else
Rows(i & ":" & i).Delete shift:=xlUp
conta = 1
End If
Next i
End Sub



a sinistra la tua sub() a destra la mia con colonna di riscontro

1 1 VERO
2 2 VERO
4 4 VERO
5 5 VERO
7 7 VERO
9 9 VERO
10 10 VERO
12 12 VERO
14 14 VERO
15 15 VERO
17 17 VERO
19 19 VERO
20 20 VERO
22 22 VERO
24 24 VERO
25 25 VERO
27 27 VERO
29 29 VERO
30 30 VERO
32 32 VERO
34 34 VERO
35 35 VERO
37 37 VERO
39 39 VERO
40 40 VERO
42 42 VERO
44 44 VERO
45 45 VERO
47 47 VERO
49 49 VERO
50 50 VERO
52 52 VERO
54 54 VERO
55 55 VERO
57 57 VERO
59 59 VERO
60 60 VERO
62 62 VERO
64 64 VERO
65 65 VERO
67 67 VERO
69 69 VERO
70 70 VERO
72 72 VERO
74 74 VERO
75 75 VERO
77 77 VERO
79 79 VERO
80 80 VERO
82 82 VERO
84 84 VERO
85 85 VERO
87 87 VERO
89 89 VERO
90 90 VERO
92 92 VERO
94 94 VERO
95 95 VERO
97 97 VERO
99 99 VERO
100 100 VERO
102 102 VERO
104 104 VERO
105 105 VERO
107 107 VERO
109 109 VERO
110 110 VERO
112 112 VERO
114 114 VERO
115 115 VERO
117 117 VERO
119 119 VERO
120 120 VERO
122 122 VERO
124 124 VERO
125 125 VERO
127 127 VERO
129 129 VERO
130 130 VERO
132 132 VERO
134 134 VERO
135 135 VERO
137 137 VERO
139 139 VERO
140 140 VERO
142 142 VERO
144 144 VERO
145 145 VERO
147 147 VERO
149 149 VERO
150 150 VERO
152 152 VERO
154 154 VERO
155 155 VERO
157 157 VERO
159 159 VERO
160 160 VERO
162 162 VERO
164 164 VERO
165 165 VERO
167 167 VERO
168 168 VERO
169 169 VERO
170 170 VERO
171 171 VERO
172 172 VERO
173 173 VERO
174 174 VERO
175 175 VERO
176 176 VERO
177 177 VERO
178 178 VERO
179 179 VERO
180 180 VERO
181 181 VERO
182 182 VERO
183 183 VERO
184 184 VERO
185 185 VERO
186 186 VERO
187 187 VERO
188 188 VERO
189 189 VERO
190 190 VERO
191 191 VERO
192 192 VERO
193 193 VERO
194 194 VERO
195 195 VERO
196 196 VERO
197 197 VERO
198 198 VERO
199 199 VERO
200 200 VERO


Ciao da locate
excel 2007 / 13
Post: 627
Registrato il: 10/10/2013
Città: VICENZA
Età: 69
Utente Senior
365
OFFLINE
13/05/2016 02:56

ah1 ah1 ah1
delle volte sono proprio pirla [SM=g27828]
l'avevo capita al copntrario [SM=x423026] [SM=x423026]
Post: 3
Registrato il: 26/11/2006
Utente Junior
excel 2007
OFFLINE
13/05/2016 22:18

ciao locatevaresino,

oggi ho provato la tua sub() ed è perfetta [SM=g27811]

ho semplicemente fatto copia e incolla ma è mia intenzione cercare di capirla per imparare meglio a creare le macro

[SM=x423017]
Post: 4
Registrato il: 26/11/2006
Utente Junior
excel 2007
OFFLINE
13/05/2016 22:23

rollis13 e federico460

[SM=x423017]

anche a voi per i vs consigli, ho provato anche le vs sub() ma non vanno bene per le mie necessità.
Post: 255
Registrato il: 16/08/2015
Città: CORDENONS
Età: 67
Utente Junior
Excel 2016-32bit Win11
OFFLINE
13/05/2016 23:44

Re:
federico460, 13/05/2016 02.56:

ah1 ah1 ah1
delle volte sono proprio pirla [SM=g27828]
l'avevo capita al contrario [SM=x423026] [SM=x423026]

E pensare che io ancora non ho capito le necessità [SM=x423018]



______________________________________________________________
C'è chi fa le COSE a CASO e chi fa CASO alle COSE (Ignoto)
Vota: 15MediaObject5,00111 1
Amministra Discussione: | Chiudi | Sposta | Cancella | Modifica | Notifica email Pagina precedente | 1 | Pagina successiva
Nuova Discussione
 | 
Rispondi
Feed | Forum | Bacheca | Album | Utenti | Cerca | Login | Registrati | Amministra
Tutti gli orari sono GMT+01:00. Adesso sono le 05:49. Versione: Stampabile | Mobile | Regolamento | Privacy
FreeForumZone [v.6.1] - Copyright © 2000-2024 FFZ srl - www.freeforumzone.com