
Private sh As Worksheet
Private col1 As Collection
Private LR As Long
Private Sub Cantiere_Click()
Dim lng As Long
Me.Opera.Clear
With sh
For lng = 6 To LR
If .Cells(lng, "c").Value = Me.Cantiere.Text Then
Me.Opera.AddItem (.Cells(lng, "F").Value)
End If
Next
End With
End Sub
Private Sub Opera_click()
Me.WBS.Clear
With sh
For r = 6 To LR
If Cells(r, "c") = Me.Cantiere.Text And Cells(r, "f") = Me.Opera.Text Then
Me.WBS.AddItem (.Cells(r, "G").Value)
End If
Next
End With
End Sub
Private Sub UserForm_Initialize()
Dim lng As Long
Set col1 = New Collection
Set sh = ThisWorkbook.Worksheets(2)
With sh
LR = .Range("c" & .Rows.Count).End(xlUp).Row
For lng = 6 To LR
On Error Resume Next
col1.Add CStr(.Cells(lng, "c").Value), CStr(.Cells(lng, "c").Value)
If Err.Number = 0 Then
Me.Cantiere.AddItem (.Cells(lng, "c").Value)
End If
Err.Number = 0
Next
End With
End Sub
Private Sub WBS_Click()
Me.Sub_wbs.Clear
With sh
For r = 6 To LR
If Cells(r, "c") = Me.Cantiere.Text And Cells(r, "f") = Me.Opera.Text And Cells(r, "g") = Me.WBS.Text Then
Me.Sub_wbs.AddItem (.Cells(r, "h").Value)
End If
Next
End With
End Sub
|
Private Rng As Range
Private Sub Cantiere_Click()
Dim finalcol As Integer
Dim cl As Object
Dim y As Integer
Dim finalrow As Integer
Dim rngattiva() As Variant
Dim rngWBS() As Variant
Me.Opera.Clear
Me.WBS.Clear
Me.Sub_wbs.Clear
finalcol = Cells(4, Columns.Count).End(xlToLeft).Column
For Each cl In Rng
If cl = Me.Cantiere.Text Then
cl.Select
cl.Offset(2, 0).Activate
y = ActiveCell.Column
finalrow = Cells(Rows.Count, y).End(xlUp).Row
End If
Next
For a = LBound(rngattiva) To UBound(rngattiva)
Me.Opera.AddItem (rngattiva(a, 1))
Next a
ActiveCell.Offset(0, 1).Activate
finalrowWBS = Cells(Rows.Count, y + 1).End(xlUp).Row
rngWBS = Range(Cells(6, y + 1), Cells(finalrowWBS, y + 1))
For h = 1 To UBound(rngWBS)
Me.WBS.AddItem (rngWBS(h, 1))
Next
End Sub
Private Sub UserForm_Initialize()
Dim c As Integer
finalcol = Cells(4, Columns.Count).End(xlToLeft).Column
Set Rng = Range(Cells(4, 6), Cells(4, finalcol))
For Each cl In Rng
If Len(cl) <> 0 Then
dato = dato & " " & cl
End If
Next
vettoreCantieri = Split(dato)
For c = 1 To UBound(vettoreCantieri)
Me.Cantiere.AddItem (vettoreCantieri(c))
' txt = txt & vettoreCantieri(c) & vbCrLf
Next c
'MsgBox txt
End Sub
|
Private sh As Worksheet
Private Sub Cantiere_Click()
Dim finalcol As Integer
Dim finalrow As Integer
Dim rngattiva() As Variant
Me.Opera.Clear
Me.WBS.Clear
Me.Sub_wbs.Clear
Set sh = Worksheets("TABCAN")
Application.ScreenUpdating = False
With sh
finalcol = .Cells(4, Columns.Count).End(xlToLeft).Column
Set Rng1 = .Range(.Cells(4, 6), .Cells(4, finalcol))
For Each cl In Rng1
If cl = Me.Cantiere.Text Then
ind = cl.Address(ReferenceStyle:=xlR1C1)
y = Val(Right(ind, 1))
finalrow = .Cells(Rows.Count, y).End(xlUp).Row
End If
Next
rngattiva = .Range(.Cells(6, y), .Cells(finalrow, y)).Value
For a = LBound(rngattiva) To UBound(rngattiva)
Me.Opera.AddItem (rngattiva(a, 1))
Next a
finalrowWBS = .Cells(Rows.Count, y + 1).End(xlUp).Row
rngWBS = .Range(.Cells(6, y + 1), .Cells(finalrowWBS, y + 1))
For h = 1 To UBound(rngWBS)
Me.WBS.AddItem (rngWBS(h, 1))
Next
End With
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Initialize()
Dim c As Integer
Set sh = Worksheets("TABCAN")
Application.ScreenUpdating = False
With sh
finalcol = .Cells(4, Columns.Count).End(xlToLeft).Column
Set Rng = .Range(.Cells(4, 6), .Cells(4, finalcol))
For Each cl In Rng
If Len(cl) <> 0 Then
dato = dato & " " & cl
End If
Next
vettoreCantieri = Split(dato)
For c = 1 To UBound(vettoreCantieri)
Me.Cantiere.AddItem (vettoreCantieri(c))
Next c
End With
Application.ScreenUpdating = True
End Sub
|
Function NumeroColonna(ByVal stringa As String) As Integer
cont = 0
For N = 1 To Len(stringa)
If IsNumeric(Right(stringa, N)) Then
cont = cont + 1
End If
Next
cont = Right(stringa, cont)
NumeroColonna = cont
End Function
For Each cl In Rng1
If cl = Me.Cantiere.Text Then
ind = cl.Address(ReferenceStyle:=xlR1C1)
y = NumeroColonna(ind) 'Val(Right(ind, 1))
finalrow = .Cells(Rows.Count, y).End(xlUp).Row
End If
Next |
Private Sub UserForm_Initialize()
Dim c As Integer
' metto il riferimento al foglio TABCAN
Set sh = Worksheets("TABCAN")
' Setto al False l'aggiornamento del video, evito lo sfarfallio di Excel
Application.ScreenUpdating = False
' con il foglio ("TABCAN")
With sh
' trovo l'ultima colonna che contiene un dato, partendo dalla riga 4
finalcol = .Cells(4, Columns.Count).End(xlToLeft).Column
' setto il Range che va dalla R4C6 alla R4C(finalcol)
Set Rng = .Range(.Cells(4, 6), .Cells(4, finalcol))
, per ciascuna cella contenuta nel range Rng controlla che
For Each cl In Rng
' Se la lunghezza del valore contenuto in cl(cella) è <>0, quindi c'è un valore
If Len(cl) <> 0 Then
' crea un stringa separando i valori da uno spazio
dato = dato & " " & cl
End If
' continua
Next
' trasformo la stringa dato in un Vettore
vettoreCantieri = Split(dato)
' ciclo tutti i valori del Vettore da 1 fino alla fine
For c = 1 To UBound(vettoreCantieri)
' e li aggiungo alla combobox Cantiere
Me.Cantiere.AddItem (vettoreCantieri(c))
' continua
Next c
'chiudo il ciclo with
End With
' aggiorno il video
Application.ScreenUpdating = True
End Sub
Private Sub Cantiere_Click()
Dim finalcol As Integer
Dim finalrow As Integer
Dim rngattiva() As Variant
Me.Opera.Clear
Me.WBS.Clear
Me.Sub_wbs.Clear
Set sh = Worksheets("TABCAN")
Application.ScreenUpdating = False
With sh
finalcol = .Cells(4, Columns.Count).End(xlToLeft).Column
Set Rng1 = .Range(.Cells(4, 6), .Cells(4, finalcol))
For Each cl In Rng1
' Se Cl è uguale al valore che ho selezionato dalla combobox Cantiere
If cl = Me.Cantiere.Text Then
' dammi l'indirizzo della cella che contiene il valore in formato R1C1
ind = cl.Address(ReferenceStyle:=xlR1C1)
' passo il valore dell'indirizzo della cella alla funzione NumeroColonna(), perchè ho bisogno
' del valore Numerico della colonna, che assegno a y
y = NumeroColonna(ind) 'Val(Right(ind, 1))
finalrow = .Cells(Rows.Count, y).End(xlUp).Row
End If
Next
rngattiva = .Range(.Cells(6, y), .Cells(finalrow, y)).Value
For a = LBound(rngattiva) To UBound(rngattiva)
Me.Opera.AddItem (rngattiva(a, 1))
Next a
' mi sposto di una colonna a Dx per trovarmi i valori di WBS
finalrowWBS = .Cells(Rows.Count, y + 1).End(xlUp).Row
rngWBS = .Range(.Cells(6, y + 1), .Cells(finalrowWBS, y + 1))
For h = 1 To UBound(rngWBS)
Me.WBS.AddItem (rngWBS(h, 1))
Next
End With
Application.ScreenUpdating = True
End Sub
Function NumeroColonna(ByVal stringa As String) As Integer
' passo alla funzione il valore dell'indirizzo della cella come stringa
' e cicla la lunghezza della stringa
For N = 1 To Len(stringa)
' se il valore N della stringa è un numero
If IsNumeric(Right(stringa, N)) Then
' sommalo a cont
cont = cont + 1
Else
' altrimenti esci
Exit For
End If
Next
' colonnafinale sara uguale al numero(cont)dei caratteri a presi a partire da DX caratteri
colonnafinale = Right(stringa, cont)
MsgBox colonnafinale
NumeroColonna = colonnafinale
End Function |
Finalcolsub_wbs=.cells(Rows.Count,y+1).End(xlup). Row Rngsub_wbs=..Range(.cells(6,y+2),.cells(finalcolsub_wbs,y+2)) For x =1 to UBound(rngsub_wbs) Me.sub_wbs.AddItem (rngsub_wbs(x,1) Next |
