| | Post: 117 | Registrato il: 04/11/2016
| Città: SASSARI | Età: 48 | Utente Junior | 2010 | | OFFLINE | |
|
24/02/2017 15:16 | |
SALVE A TUTTI ,
E' possibile riuscire a mischiare ? ,
ess.
range "a1:a20"
tutte le celle piene con numeri, in ordine crescente da 1 a 20
riuscire appunto a mischiarli tra loro |
|
| | Post: 3.716 | Registrato il: 13/03/2012
| Città: LIVORNO | Età: 78 | Utente Master | 2010 | | OFFLINE | |
|
24/02/2017 16:14 | |
Sub sortrange()
Dim arr() As Integer, arr1()
Dim first As Integer, last As Integer
Set orig = Range("A1:A20")
arr1 = orig.Value
first = orig.Row
last = first + orig.Rows.Count - 1
arr = RandomArray(first, last)
For r = first To last
Cells(r, "A") = arr1(arr(r), 1)
Next
End Sub
----------
Win 10 - Excel 2010
allega un file di esempio, guadagnerai tempo tu e lo farai risparmiare a chi ti aiuta |
| | Post: 2.558 | Registrato il: 03/04/2013
| Utente Veteran | Excel 2000 - 2013 | | OFFLINE | |
|
24/02/2017 16:32 | |
... mischiare Range "A1:A20"
Option Explicit
Sub Random()
Application.ScreenUpdating = False
Dim r As Byte, n As Byte, arNum() As Byte
Dim j As Integer
ReDim arNum(1 To 20)
For j = 1 To 20
arNum(j) = j
Next j
For j = 20 To 1 Step -1
r = Int((j * Rnd) + 1)
n = arNum(r)
arNum(r) = arNum(j)
arNum(j) = n
Cells(j, 1) = n
Next j
Erase arNum
Application.ScreenUpdating = True
End Sub
... Tutte le celle piene con numeri, in ordine crescente da 1 a 20
Option Explicit
Sub Cresecete()
Application.ScreenUpdating = False
Dim x As Byte
For x = 1 To 20
Cells(x, 1) = x
Next x
Application.ScreenUpdating = False
End Sub
Windows XP - Excel 2000
Windows 10 - Excel 2013 |
| | Post: 117 | Registrato il: 04/11/2016
| Città: SASSARI | Età: 48 | Utente Junior | 2010 | | OFFLINE | |
|
24/02/2017 16:45 | |
SICURAMENTE MI SONO ESPRESSO MALE,
le celle nel range a1:a20 sono gia piene,
da 1 a 20 era un esempio,
possono esserci qualsiasi numeri, io vorrei che quei numeri vengano mischiati tra loro
ess:
1
2
3
4
5
6
7
ecc...
diventa
4
6
7
3
2
5
1
ecc
|
| | Post: 118 | Registrato il: 04/11/2016
| Città: SASSARI | Età: 48 | Utente Junior | 2010 | | OFFLINE | |
|
24/02/2017 17:09 | |
qualche soluzione? |
| | Post: 2.559 | Registrato il: 03/04/2013
| Utente Veteran | Excel 2000 - 2013 | | OFFLINE | |
|
24/02/2017 18:16 | |
... incrocio le dite e:
Option Explicit
Sub Random()
Application.ScreenUpdating = False
Dim r As Integer, n As Integer, arNum() As Integer, j As Integer, nx As Integer
Columns("B:B").ClearContents
nx = 1
ReDim arNum(1 To 20)
For j = 1 To 20
If Cells(j, 1) <> "" Then
arNum(nx) = Cells(j, 1)
nx = nx + 1
End If
Next j
For j = nx - 1 To 1 Step -1
r = Int((j * Rnd) + 1)
n = arNum(r)
arNum(r) = arNum(j)
arNum(j) = n
Cells(j, 2) = n
Next j
Erase arNum
Application.ScreenUpdating = True
End Sub
Giuseppe
Windows XP - Excel 2000
Windows 10 - Excel 2013 |
| | Post: 2.560 | Registrato il: 03/04/2013
| Utente Veteran | Excel 2000 - 2013 | | OFFLINE | |
|
24/02/2017 18:29 | |
Con ordinamento:
Option Explicit
Sub Random()
Application.ScreenUpdating = False
Dim r As Integer, n As Integer, arNum() As Integer, j As Integer, nx As Integer
Columns("B:B").ClearContents
nx = 1
ReDim arNum(1 To 20)
For j = 1 To 20
If Cells(j, 1) <> "" Then
arNum(nx) = Cells(j, 1)
nx = nx + 1
End If
Next j
For j = nx - 1 To 1 Step -1
r = Int((j * Rnd) + 1)
n = arNum(r)
arNum(r) = arNum(j)
arNum(j) = n
Cells(j, 2) = n
Next j
Erase arNum
Columns("B:B").Select
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range("B1:B20"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveSheet.Sort
.SetRange Range("B1:B20")
.Apply
End With
Range("B1").Select
Application.ScreenUpdating = True
End Sub
Windows XP - Excel 2000
Windows 10 - Excel 2013 |
| | Post: 3.717 | Registrato il: 13/03/2012
| Città: LIVORNO | Età: 78 | Utente Master | 2010 | | OFFLINE | |
|
24/02/2017 19:56 | |
ema.cab, 24/02/2017 17.09:
qualche soluzione?
l'hai provata la mia ? cosa non funziona ?
----------
Win 10 - Excel 2010
allega un file di esempio, guadagnerai tempo tu e lo farai risparmiare a chi ti aiuta |
| | Post: 119 | Registrato il: 04/11/2016
| Città: SASSARI | Età: 48 | Utente Junior | 2010 | | OFFLINE | |
|
24/02/2017 20:21 | |
le celle nel range a1:a20 sono gia piene,
da 1 a 20 era un esempio,
possono esserci qualsiasi numeri, io vorrei che quei numeri vengano mischiati tra loro
ess:
1
2
3
4
5
6
7
ecc...
diventa
4
6
7
3
2
5
1
ecc
LA SOLUZIONE DI #GiuseppeMN
va bene solo che non riesco a capire come fare, se voglio spostare la macro in altre colonne ess: "Ch43:Ch79"
[Modificato da ema.cab 25/02/2017 01:41] |
| | Post: 120 | Registrato il: 04/11/2016
| Città: SASSARI | Età: 48 | Utente Junior | 2010 | | OFFLINE | |
|
25/02/2017 01:40 | |
Nel range (cf43:cf79) inserirò dei numeri,
E in (ch43:ch79) la macro andra a mischiarli... pensate si possa fare?.... |
| | Post: 3.719 | Registrato il: 13/03/2012
| Città: LIVORNO | Età: 78 | Utente Master | 2010 | | OFFLINE | |
|
25/02/2017 10:18 | |
proprio non le leggi le risposte, ti piace solo fare domande
----------
Win 10 - Excel 2010
allega un file di esempio, guadagnerai tempo tu e lo farai risparmiare a chi ti aiuta |
| | Post: 2.561 | Registrato il: 03/04/2013
| Utente Veteran | Excel 2000 - 2013 | | OFFLINE | |
|
25/02/2017 10:51 | |
ema.cab, scrive:
Nel range (cf43:cf79) inserirò dei numeri,
E in (ch43:ch79) la macro andra a mischiarli; pensate si possa fare?
Buona giornata, Ema.Cab;
credo esistano molti modi; quello che ho utilizzato è:
- posizionare il Cursore sulla prima Cella da valutare (nel Tuo esempio CF43)
Quindi, potresti provare con:
Option Explicit
Sub Random()
Application.ScreenUpdating = False
Dim PRg As Byte, Cln As Byte, URg As Byte ' se il numero di Righe da valutare supera le 255 Righe, definire come Integer
Dim r As Integer, n As Integer, j As Integer, nx As Integer, nxx As Integer
Dim ArNum() As Integer
PRg = ActiveCell.Row
Cln = ActiveCell.Column
URg = PRg
Do While Cells(URg, Cln) <> ""
URg = URg + 1
Loop
URg = URg - 1
Range(Cells(PRg, Cln + 2), Cells(URg, Cln + 2)).ClearContents
nx = 1
ReDim ArNum(URg)
For j = PRg To URg
If Cells(j, Cln) <> "" Then
ArNum(nx) = Cells(j, Cln)
nx = nx + 1
End If
Next j
nx = nx - 1
nxx = URg
For j = nx To 1 Step -1
r = Int((j * Rnd) + 1)
n = ArNum(r)
ArNum(r) = ArNum(j)
ArNum(j) = n
Cells(nxx, Cln + 2) = ArNum(j)
nxx = nxx - 1
Next j
Erase ArNum
Cells(PRg, Cln).Select
Application.ScreenUpdating = True
End Sub
==========================================================================================
Buona giornata, Patel;
sicuramente è una mia cattiva applicazione, ma, lanciando il Codice VBA "sortrange" mi rende l'errore come in allegato.
Dove sbaglio? Grazie della Risposta che potrai dedicarmi.
A disposizione.
Buon fine settimana.
Giuseppe
Windows XP - Excel 2000
Windows 10 - Excel 2013 |
| | Post: 121 | Registrato il: 04/11/2016
| Città: SASSARI | Età: 48 | Utente Junior | 2010 | | OFFLINE | |
|
25/02/2017 11:44 | |
GRAZIE MILLE GiuseppeMN
SI cosi' mi va alla grande.
GRAZIE ANCORA
ciao PATEL45
SI che le leggo le risposte, e ti ho risposto con:
le celle nel range a1:a20 sono gia piene,
da 1 a 20 era un esempio, ecc.....
comunque grazie PATEL del tuo tempo |
| | Post: 3.720 | Registrato il: 13/03/2012
| Città: LIVORNO | Età: 78 | Utente Master | 2010 | | OFFLINE | |
|
25/02/2017 12:33 | |
la prima risposta al tuo quesito è la mia, potevi rispondere che non funzionava e ti avrei allegato la funzione mancante
Function RandomArray(first As Integer, last As Integer) As Integer()
Dim i As Integer, J As Integer, temp As Integer
ReDim result(first To last) As Integer
For i = first To last: result(i) = i: Next
For i = last To first Step -1
J = Rnd * (last - first + 1) + first
If J > last Then J = last
temp = result(i): result(i) = result(J): result(J) = temp
Next
RandomArray = result
End Function
invece tu hai risposto a Giuseppe, comunque vedo che hai risolto.
----------
Win 10 - Excel 2010
allega un file di esempio, guadagnerai tempo tu e lo farai risparmiare a chi ti aiuta |
| | Post: 122 | Registrato il: 04/11/2016
| Città: SASSARI | Età: 48 | Utente Junior | 2010 | | OFFLINE | |
|
25/02/2017 12:36 | |
scusami tanto Patel, sono mortificato,
NON ERA MIA INTENZIONE MANCARTI DI RISPETTO,
tramite messaggi a volte si fa fatica e confusione.,
scusami ancora e grazie della tua disponobilita'.. |
|
|