Condividi:        

macro che ricerca dato non assegnato

Vuoi potenziare i tuoi documenti Word? Non sai come si fa una macro in Excel? Devi creare una presentazione in PowerPoint?
Oppure sei passato a OpenOffice e non sei sicuro di come lavorare al meglio?

Moderatori: Anthony47, Flash30005

Re: macro che ricerca dato non assegnato

Postdi Flash30005 » 10/11/11 22:35

La macro per il riposo potrebbe essere questa
Codice: Seleziona tutto
Sub RiposoCanc()
Set Ws1 = Worksheets("Foglio3")
UR1 = Ws1.Range("A" & Rows.Count).End(xlUp).Row
For RR1 = 1 To UR1
    If Mid(Ws1.Cells(RR1, 2).Value, 1, 6) = "RIPOSO" Then
        For CC1 = 3 To 7
            If Mid(Ws1.Cells(RR1, CC1).Value, 1, 6) = "RIPOSO" Then
                Ws1.Cells(RR1, 2).Value = ""
                Ws1.Cells(RR1, CC1).Value = ""
            End If
        Next CC1
    End If
Next RR1
End Sub


Ho dei dubbi per l'altra condizione
martin ha scritto:un'altra : if colonna b terzo rigo = "21:00-02:00" o "19-02" and colonna b terzo rigo = "10-14" o 10-15 o 10-18 Then Selection.ClearContents
(chi fa la notte non fa la mattina)


Ma il controllo lo deve fare, come dici, sempre sulla colonna B per tutti quegli orari?
quindi non è un "And" ma tutti "Or"

Ciao
Flash
Win10 + Office 2010 Ita
"Fotografica" al servizio dell'immagine
Avatar utente
Flash30005
Moderatore
 
Post: 8517
Iscritto il: 27/09/07 11:44
Località: Roma +o-

Sponsor
 

Re: macro che ricerca dato non assegnato

Postdi martin » 11/11/11 00:50

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
martin
Utente Senior
 
Post: 108
Iscritto il: 03/12/08 17:04

Re: macro che ricerca dato non assegnato

Postdi Flash30005 » 11/11/11 08:20

Non avevo capito dal post precedente che la scansione dei Riposi doveva proseguire con le altre colonne ma solo se Bx era Riposo
quindi è sufficiente aggiungere un For next per ottenere quello che desideri e senza dover modificare, unificando, la stringa Riposo in quanto la macro prende solo i primi 6 caratteri della stringa escludendo la numerazione
prova questa
Codice: Seleziona tutto
Sub RiposoCanc()
Set Ws1 = Worksheets("Foglio3")
UR1 = Ws1.Range("A" & Rows.Count).End(xlUp).Row
For RR1 = 1 To UR1
For CC = 2 To 6
    If Mid(Ws1.Cells(RR1, CC).Value, 1, 6) = "RIPOSO" Then
        For CC1 = CC + 1 To 7
            If Mid(Ws1.Cells(RR1, CC1).Value, 1, 6) = "RIPOSO" Then
                Ws1.Cells(RR1, 2).Value = ""
                Ws1.Cells(RR1, CC1).Value = ""
            End If
        Next CC1
    End If
    Next CC
Next RR1


ciao
Flash
Win10 + Office 2010 Ita
"Fotografica" al servizio dell'immagine
Avatar utente
Flash30005
Moderatore
 
Post: 8517
Iscritto il: 27/09/07 11:44
Località: Roma +o-

Re: macro che ricerca dato non assegnato

Postdi martin » 11/11/11 10:43

ok!
era quello che cercavo devo ora mettere tutte le mie condizioni
ecco alcune:
Codice: Seleziona tutto
'segue chi fa notte non fa mattina

Set Ws1 = Worksheets("Foglio6")
UR1 = Ws1.Range("A" & Rows.Count).End(xlUp).Row
For RR1 = 1 To UR1
For cc = 2 To 6
    If Mid(Ws1.Cells(RR1, cc).Value, 1, 11) = "21:00-02:00" Then
        For CC1 = cc + 1 To 8
            If Mid(Ws1.Cells(RR1, CC1).Value, 1, 13) = "10-14 - 21:02" Then
                Ws1.Cells(RR1, 2).Value = ""
                               
            End If
        Next CC1
    End If
    Next cc
Next RR1
' chi ha gia avuto un riposo, no te ne do un'altro!!!

Set Ws1 = Worksheets("Foglio6")
UR1 = Ws1.Range("A" & Rows.Count).End(xlUp).Row
For RR1 = 1 To UR1
For cc = 2 To 6
    If Mid(Ws1.Cells(RR1, cc).Value, 1, 6) = "RIPOSO" Then
        For CC1 = cc + 1 To 7
            If Mid(Ws1.Cells(RR1, CC1).Value, 1, 6) = "RIPOSO" Then
                Ws1.Cells(RR1, 2).Value = ""
               
            End If
        Next CC1
    End If
    Next cc
Next RR1
'segue anche questo fa mattina e sera non puo certo rifarne un'altra!!!
Set Ws1 = Worksheets("Foglio6")
UR1 = Ws1.Range("A" & Rows.Count).End(xlUp).Row
For RR1 = 1 To UR1
For cc = 2 To 6
    If Mid(Ws1.Cells(RR1, cc).Value, 1, 13) = "10-14 - 21:02" Then
        For CC1 = cc + 1 To 8
            If Mid(Ws1.Cells(RR1, CC1).Value, 1, 13) = "10-14 - 21:02" Then
                Ws1.Cells(RR1, 2).Value = ""
                               
            End If
        Next CC1
    End If
    Next cc
Next RR1
'segue anche questo fa la notte fino alle 4 non fa la mattina!!

Set Ws1 = Worksheets("Foglio6")
UR1 = Ws1.Range("A" & Rows.Count).End(xlUp).Row
For RR1 = 1 To UR1
For cc = 2 To 6
    If Mid(Ws1.Cells(RR1, cc).Value, 1, 11) = "21:00-04:00" Then
        For CC1 = cc + 1 To 8
            If Mid(Ws1.Cells(RR1, CC1).Value, 1, 13) = "10-14 - 21:02" Then
                Ws1.Cells(RR1, 2).Value = ""
                               
            End If
        Next CC1
    End If
    Next cc
Next RR1
' anche questo a fatto doppio turno no fa altri mattina!!!

Set Ws1 = Worksheets("Foglio6")
UR1 = Ws1.Range("A" & Rows.Count).End(xlUp).Row
For RR1 = 1 To UR1
For cc = 2 To 6
    If Mid(Ws1.Cells(RR1, cc).Value, 1, 13) = "10-14 - 21:04" Then
        For CC1 = cc + 1 To 8
            If Mid(Ws1.Cells(RR1, CC1).Value, 1, 13) = "10-14 - 21:02" Then
                Ws1.Cells(RR1, 2).Value = ""
                               
            End If
        Next CC1
    End If
    Next cc
Next RR1

' segue altre condizioni....  alla fine gli orari rimanenti verranno assegnati



questa va aggiunta alla macro principale una per ogni giorno cosi potro completare senza fare errori e in tempi ristretti Risolto.
grazie tante flash :)
ma sono sicuro che ti disturbero' di nuovo
perche' trovero altro intoppo prima di finire a presto
martin
martin
Utente Senior
 
Post: 108
Iscritto il: 03/12/08 17:04

Re: macro che ricerca dato non assegnato

Postdi Flash30005 » 11/11/11 11:01

Secondo me potrebbero essere tutti nella stessa macro con le condizioni OR
invece che ripetere la macro per ogni giorno

ciao
Flash
Win10 + Office 2010 Ita
"Fotografica" al servizio dell'immagine
Avatar utente
Flash30005
Moderatore
 
Post: 8517
Iscritto il: 27/09/07 11:44
Località: Roma +o-

Re: macro che ricerca dato non assegnato

Postdi martin » 11/11/11 14:16

infatti è in previsione...
adesso mi interessa questa macro che devo ancora modificare per qualche altra esigenza
poi ne faro ( :D ne farò!!!... ho un amico che si chiama flash lui sicuramente mi aiuterà.. :eeh:) una che servira per fare tutto in automatico .
quando finisco ti faccio sapere
ciao a presto
martin
Utente Senior
 
Post: 108
Iscritto il: 03/12/08 17:04

Precedente

Torna a Applicazioni Office Windows


Topic correlati a "macro che ricerca dato non assegnato":


Chi c’è in linea

Visitano il forum: papiriof e 37 ospiti