|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Jul 2007
Messaggi: 1092
|
[vba] not in array
Ciao a tutti. Scusate la domanda sicuramente banale ma anche google non mi è stato d'aiuto.
Esempio Codice:
array = array(1,3,5) for i = 1 to 10 if i not in array then msgbox i end if next i Ultima modifica di john_revelator : 03-06-2009 alle 13:47. |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Jul 2007
Messaggi: 1092
|
Continuando a cercare ho trovato una possibile soluzione
http://www.dailydoseofexcel.com/arch...ction-members/ Codice:
Sub exclusion() Dim SheetsToKeep As String Dim i As Long Dim ws As Worksheet ‘Names of sheets to keep ‘note the last comma SheetsToKeep = “Save1,Save2,Save3,” ‘Loop through the sheets For Each ws In ThisWorkbook.Worksheets ‘See if the sheet’s name is in the string ‘don’t forget the comma If InStr(1, SheetsToKeep, ws.Name & “,”) = 0 Then ws.Delete End If Next ws End Sub ![]() |
![]() |
![]() |
![]() |
#3 | |
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Quote:
Codice:
Private Function TrovaInArray(valore As Variant, A() As Variant) As Long Dim i As Long For i = LBound(A) To UBound(A) If valore = A(i) Then TrovaInArray = i Exit Function End If Next i TrovaInArray = -1 End Function E qui, come usarla : Codice:
Dim mioArray() As Variant mioArray = Array(1, 3, 5) Dim i As Integer For i = 1 To 10 If TrovaInArray(i, mioArray) = -1 Then MsgBox i Next i ![]() |
|
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Jul 2007
Messaggi: 1092
|
Ah, quindi non esiste nessun costrutto precotto e occorre costruirsi una funzioncina ad hoc. Mi inchino come sempre al tuo sapere. Grazie mille Marco.
![]() |
![]() |
![]() |
![]() |
#5 | |
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Quote:
in VB.NET ad esempio il tutto si ridurrebbe ad una riga di codice : Codice:
Dim mioArray() As Integer = {1, 3, 5} For i As Integer = 1 To 10 If Not mioArray.Contains(i) Then MsgBox(i) Next ![]() |
|
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Jul 2007
Messaggi: 1092
|
Decisamente più pratico. Bisogna che prenda coraggio e provi a iniziare a studiare vb.net. Grazie ancora.
![]() |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 05:31.