| | Post: 1 | Registrato il: 02/11/2020
| Utente Junior | 2019 | | OFFLINE | |
|
03/11/2020 00:37 | |
ciao a tutti
premetto che sono alle prime esperienze con VBA.
ho provato ma non ci sono riuscito!
mi servirebbe un codice che dato un elenco di numeri o stringhe possa confrontare due celle consecutive per righe e se in presenza di valori uguali copiare i valori nella colonna seguente nelle stesse righe.
allego un breve esempio.
spero di essere stato chiaro
grazie per il contributo che tutti voi date, è il mio primo accesso al forum
ciao |
|
|
03/11/2020 00:48 | |
In base alla richiesta, le celle B4,B7,B12 dovrebbero essere vuote? Forse inserendo un'altro confronto trà la cella precedente e quella attuale... Sub a()
Dim Ur, x
Ur = Range("A" & Rows.Count).End(xlUp).Row
For x = 2 To Ur
If Cells(x, 1) = Cells(x + 1, 1) Then Cells(x, 2) = Cells(x, 1)
If Cells(x - 1, 1) = Cells(x, 1) Then Cells(x, 2) = Cells(x, 1)
Next
End Sub |
| | Post: 1 | Registrato il: 02/11/2020
| Utente Junior | 2019 | | OFFLINE | |
|
03/11/2020 10:50 | |
Grazie mille ABCDEF@Excel !!
Come anticipati sono alle prime armi con VBA.
Adesso vorrei fare un altro passaggio: indicare nella colonna successiva quante volte lo stesso valore si è ripetuto (quindi la funzione dovrebbe essere conta celle con lo stesso valore e scrivi il valore e il risultato del conta)
Allego esempio in excel, desiderato è risultato 2
Ieri ho scoperto questo forum e devo dire che è molto interessante !
Bravi a tutti
|
|
03/11/2020 14:09 | |
Prova... Sub a()
Dim Ur, x, r
Ur = Range("A" & Rows.Count).End(xlUp).Row
For x = 2 To Ur
If Cells(x, 1) = Cells(x + 1, 1) Then Cells(x, 2) = Cells(x, 1): If r = "" Then r = x
If Cells(x - 1, 1) = Cells(x, 1) Then Cells(x, 2) = Cells(x, 1)
If Cells(x, 1) <> Cells(x + 1, 1) And r <> "" Then
Cells(x, 3) = Cells(x, 1)
Cells(x, 4) = Application.WorksheetFunction.CountIf(Range("B" & r & ":B" & x), Cells(x, 2))
r = ""
End If
Next
End Sub
|
| | Post: 2 | Registrato il: 02/11/2020
| Utente Junior | 2019 | | OFFLINE | |
|
03/11/2020 15:05 | |
Grazie funziona !!
in realtà la richiesta che ti ho fatto era parziale perchè volevo sbattermi anche io...per imparare qualche cosa!
ci sono riuscito a fare quello che volevo..
Ti ringrazio ancora !
ciao |
|
|