no
io ho tradotto cosi:
una delle condizioni è: " if colonna b terzo rigo = riposo1 o riposo2 o riposo3 o riposo4 and colonna c, d, e,f,g,h terzo rigo = riposo1 o riposo2 o riposo3 o riposo 4 Then Selection.ClearContents.
- Codice: Seleziona tutto
Z = Range("b3")
i = Range("c3")
k = Range("d3")
l = Range("e3")
o = Range("f3")
P = Range("g3")
q = Range("h3")
m1 = "RIPOSO1"
m2 = "RIPOSO2"
m3 = "RIPOSO3"
m4 = "RIPOSO4"
If Z = m1 And i = m1 Then Selection.ClearContents
If Z = m1 And i = m2 Then Selection.ClearContents
If Z = m1 And i = m3 Then Selection.ClearContents
If Z = m1 And i = m4 Then Selection.ClearContents
If Z = m2 And i = m1 Then Selection.ClearContents
If Z = m2 And i = m2 Then Selection.ClearContents
If Z = m2 And i = m3 Then Selection.ClearContents
If Z = m2 And i = m4 Then Selection.ClearContents
If Z = m3 And i = m1 Then Selection.ClearContents
If Z = m3 And i = m2 Then Selection.ClearContents
If Z = m3 And i = m3 Then Selection.ClearContents
If Z = m3 And i = m4 Then Selection.ClearContents
If Z = m4 And i = m1 Then Selection.ClearContents
If Z = m4 And i = m2 Then Selection.ClearContents
If Z = m4 And i = m3 Then Selection.ClearContents
If Z = m4 And i = m4 Then Selection.ClearContents
If k = m1 And i = m1 Then Selection.ClearContents
If k = m1 And i = m2 Then Selection.ClearContents
If k = m1 And i = m3 Then Selection.ClearContents
If k = m1 And i = m4 Then Selection.ClearContents
If k = m2 And i = m1 Then Selection.ClearContents
If k = m2 And i = m2 Then Selection.ClearContents
If k = m2 And i = m3 Then Selection.ClearContents
If k = m2 And i = m4 Then Selection.ClearContents
If k = m3 And i = m1 Then Selection.ClearContents
If k = m3 And i = m2 Then Selection.ClearContents
If k = m3 And i = m3 Then Selection.ClearContents
If k = m3 And i = m4 Then Selection.ClearContents
If k = m4 And i = m1 Then Selection.ClearContents
If k = m4 And i = m2 Then Selection.ClearContents
If k = m4 And i = m3 Then Selection.ClearContents
If k = m4 And i = m4 Then Selection.ClearContents
'continua con l = Range("e3") o = Range("f3") P = Range("g3") q = Range("h3")
diciamo per tagliare la testa al toro come dici tu
che volevo una abbrevazione di tutto questo
oppure se voglio evitare tutti questi confronti si deve modificare il testo di "riposo1,riposo2,riposo3,riposo4" in riposo,riposo,riposo,riposo ma mi devi aiutare a modificare questa macro in modo che mi consideri nel confronto
i 4 riposi perche in questa condizione me ne darebbe solo 1 visto che confronta il valore univoco se manca!!
- Codice: Seleziona tutto
Sub CopiaSeAssente()
Set ws1 = Worksheets("Foglio1")
Set Ws2 = Worksheets("Foglio2")
UR1 = ws1.Range("A" & Rows.Count).End(xlUp).Row
For RR1 = 1 To UR1
UR2 = Ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
If UR2 < 3 Then UR2 = 3 '<<<< aggiunegendo questa interviene se il foglio2 è vuoto
TR = 0
CV = 0
TCV = 0
Val1 = ws1.Cells(RR1, 1).Value
For RR2 = 3 To UR2
If UCase(Val1) = UCase(Ws2.Cells(RR2, 1).Value) Then TR = 1 '<<< modificando questa si evita di trascrivere se il carattere è maiuscolo o miniscolo
If Ws2.Cells(RR2, 1).Value = 0 Then
If TCV = 0 Then Riga = RR2
TCV = 1
End If
Next RR2
If TCV = 1 And TR = 0 Then Ws2.Cells(Riga, 1).Value = Val1
Next RR1
End Sub
questa invece è la macro test funzionante con if then
che sto cercando di completare
- Codice: Seleziona tutto
Sub CopiacSeAssente()
1:
Set Ws1 = Worksheets("Foglio3")
Set Ws2 = Worksheets("Foglio6")
Sheets("Foglio3").Select
Dim URiga As String
Dim Riga, R, Colonna
Dim Matrice()
Dim Temp1, Temp2
URiga = Range("A1").End(xlDown).Address
' richiesta della colonna da mescolare
Colonna = 2
' creazione di una Matrice a due dimensioni
' nella prima dimensione verranno raccolti i dati dalla Colonna indicata
' nella seconda colonna verranno memorizzati dei numeri casuali
With Range("A1:" & URiga)
ReDim Matrice(1 To .Rows.Count, 1 To 2)
Randomize
' riempimento della matrice
For Riga = 1 To .Rows.Count
Matrice(Riga, 1) = .Item(Riga, Colonna)
Matrice(Riga, 2) = Rnd()
Next
' ordinamento della matrice in base alla seconda colonna (i numeri casuali)
For Riga = 1 To UBound(Matrice, 1) - 1
For R = Riga + 1 To UBound(Matrice, 1)
If Matrice(Riga, 2) > Matrice(R, 2) Then
Temp1 = Matrice(Riga, 1)
Temp2 = Matrice(Riga, 2)
Matrice(Riga, 1) = Matrice(R, 1)
Matrice(Riga, 2) = Matrice(R, 2)
Matrice(R, 1) = Temp1
Matrice(R, 2) = Temp2
End If
Next
Next
' trascrizione sul foglio della prima colonna (i dati precedentemente raccolti)
For Riga = 1 To UBound(Matrice, 1)
.Item(Riga, Colonna) = Matrice(Riga, 1)
Next
End With
Sheets("Foglio6").Select
UR1 = Ws1.Range("b" & Rows.Count).End(xlUp).Row
For RR1 = 1 To UR1
UR2 = Ws2.Range("c" & Rows.Count).End(xlUp).Row + 1
If UR2 < 3 Then UR2 = 3 '<<<< aggiunegendo questa interviene se il foglio2 è vuoto
TR = 0
CV = 0
TCV = 0
val1 = Ws1.Cells(RR1, 2).Value
RR2 = Range("a1")
If UCase(val1) = UCase(Ws2.Cells(RR2, 3).Value) Then TR = 1 '<<< modificando questa si evita di trascrivere se il carattere è maiuscolo o miniscolo
If Ws2.Cells(RR2, 3).Value = 0 Then
If TCV = 0 Then Riga = RR2
TCV = 1
End If
If TCV = 1 And TR = 0 Then Ws2.Cells(Riga, 3).Value = val1
x = Range("a1")
Z = Range("b3")
i = Range("c3")
k = Range("d3")
l = Range("e3")
o = Range("f3")
P = Range("g3")
q = Range("h3")
m1 = "RIPOSO1"
m2 = "RIPOSO2"
m3 = "RIPOSO3"
m4 = "RIPOSO4"
If Z = m1 And i = m1 Then Selection.ClearContents
If Z = m1 And i = m2 Then Selection.ClearContents
If Z = m1 And i = m3 Then Selection.ClearContents
If Z = m1 And i = m4 Then Selection.ClearContents
If Z = m2 And i = m1 Then Selection.ClearContents
If Z = m2 And i = m2 Then Selection.ClearContents
If Z = m2 And i = m3 Then Selection.ClearContents
If Z = m2 And i = m4 Then Selection.ClearContents
If Z = m3 And i = m1 Then Selection.ClearContents
If Z = m3 And i = m2 Then Selection.ClearContents
If Z = m3 And i = m3 Then Selection.ClearContents
If Z = m3 And i = m4 Then Selection.ClearContents
If Z = m4 And i = m1 Then Selection.ClearContents
If Z = m4 And i = m2 Then Selection.ClearContents
If Z = m4 And i = m3 Then Selection.ClearContents
If Z = m4 And i = m4 Then Selection.ClearContents
If k = m1 And i = m1 Then Selection.ClearContents
If k = m1 And i = m2 Then Selection.ClearContents
If k = m1 And i = m3 Then Selection.ClearContents
If k = m1 And i = m4 Then Selection.ClearContents
If k = m2 And i = m1 Then Selection.ClearContents
If k = m2 And i = m2 Then Selection.ClearContents
If k = m2 And i = m3 Then Selection.ClearContents
If k = m2 And i = m4 Then Selection.ClearContents
If k = m3 And i = m1 Then Selection.ClearContents
If k = m3 And i = m2 Then Selection.ClearContents
If k = m3 And i = m3 Then Selection.ClearContents
If k = m3 And i = m4 Then Selection.ClearContents
If k = m4 And i = m1 Then Selection.ClearContents
If k = m4 And i = m2 Then Selection.ClearContents
If k = m4 And i = m3 Then Selection.ClearContents
If k = m4 And i = m4 Then Selection.ClearContents
'continua con l = Range("e3") o = Range("f3") P = Range("g3") q = Range("h3")
Next RR1
End Sub
ciao