scusa mauro ma non ti capisco potresti spiegarmi?
questo è tutto il codice
Option Explicit
'dichiaro una variabile
'visibile da tutta la UserForm
Private colCol As Collection
Private wk As Workbook
Private sh As Worksheet
Dim rng As Range
Dim c As Range
Private Sub CommandButton4_Click()
Unload Me
Inizio.Show
End Sub
Private Sub TextBox19_Change()
On Error Resume Next
'TextBox20.Value = TextBox21.Value - TextBox20.Value
'TextBox20.Text = Format(TextBox5, "#,##0.00")
End Sub
Private Sub TextBox4_Change()
End Sub
'evento che si verifica
'alla creazione della userForm
Private Sub UserForm_Initialize()
'dichiaro le variabili
Dim lUltRiga As Long
Dim v As Variant
Dim hWnd As Long
hWnd = FindWindow(vbNullString, Me.Caption)
SetWindowLong hWnd, -16, &H84080080
DrawMenuBar hWnd
'metto riferimenti al Workbook
'che contiene il codice
' e al Foglio con i dati
Set wk = ThisWorkbook
With wk
Set sh = .Worksheets("Archivio")
End With
'creo la collection
Set colCol = New Collection
With sh
'trovo l'utima riga con
'dati in colonna A
'nel Foglio1
lUltRiga = .Range("A" & _
.Rows.Count).End(xlUp).Row
'metto un riferimento al range
'con dati
Set rng = .Range("A2:A" & lUltRiga)
'ciclo il Range e carico la
'collection
On Error Resume Next
For Each c In rng
colCol.Add c.Value, CStr(c.Value)
Next
End With
'dichiaro il numero di
'colonne della ListBox2
With Me.ListBox2
.ColumnCount = 4
.ColumnWidths = "60;0;80;0"
End With
'carico la listBox1
With Me.ListBox1
For Each v In colCol
.AddItem v
Next
End With
End Sub
'evento che si verifica al click
'sulla ListBox1
Private Sub ListBox1_Click()
Dim lCont As Long
Dim lng As Long
Dim d1 As Double
Dim x As Long
lCont = 0
With Me
'pulisco ListBox1
'e TextBox1
'.TextBox1.Text = ""
For x = 1 To 15
Controls("TextBox" & x) = ""
Next x
.ListBox2.Clear
.ListBox3.Clear
'carico i nuovi valori
.TextBox1.Text = .ListBox1.Text
'ciclo i dati
For Each c In rng
'se ho corrispondenza
If c.Value = .ListBox1.Text Then
'carico la ListBox2
.ListBox2.AddItem
.ListBox2.List(lCont, 0) = c.Offset(0, 1).Value
.ListBox2.List(lCont, 1) = Format(c.Offset(0, 14).Value, "#,###.00")
.ListBox2.List(lCont, 2) = c.Offset(0, 8).Value
'.ListBox2.List(lCont, 2) = Format(c.Offset(0, 14).Value, "#,###.00")
'.ListBox2.List(lCont, 3) = Format(c.Offset(0, 15).Value, "#,###.00")
lCont = lCont + 1
End If
Next
End With
For lng = 0 To Me.ListBox2.ListCount - 1
d1 = d1 + Me.ListBox2.List(lng, 1)
Next
With Me
.TextBox2.Text = Format(d1, "#,###.00")
End With
End Sub
Private Sub ListBox2_Click()
Dim lng As Long
Dim d2 As Double
Dim d3 As Double
Dim d4 As Double
With Me.ListBox3
'aggiungo una riga a ListBox2
.AddItem
'passo i valori da ListBox1 a ListBox2
.List(.ListCount - 1, 0) = Me.ListBox2.List(Me.ListBox2.ListIndex, 0)
.List(.ListCount - 1, 1) = Me.ListBox2.List(Me.ListBox2.ListIndex, 1)
End With
With Me.ListBox3
.ColumnCount = 2
.ColumnWidths = "60;60"
End With
On Error Resume Next
For lng = 0 To Me.ListBox3.ListCount - 1
d2 = d2 + Me.ListBox3.List(lng, 1) 'lavoro totale
'd3 = d3 + Me.ListBox2.List(lng, 2)
'd4 = d4 + Me.ListBox2.List(lng, 3)
Next
With Me
.TextBox3.Text = Format(d2, "#,##0.00")
'.TextBox4.Text = Format(d3, "#,##0.00")
'TextBox5.Text = Format(d4, "#,##0.00")
End With
End Sub
Private Sub CommandButton2_Click()
Dim lRiga As Long
Dim lng1 As Long
Dim x As Long
Dim s As String
Dim lng As Long
Dim col As Long
lRiga = .Range("A" & .Rows.Count).End(xlUp).Row
For lng1 = 2 To lRiga
If .Range("A" & lng1).Value = Me.ListBox1.Text And _
.Range("C" & lng1).Value = CDate(Me.ListBox2.Text) Then
col = 12
For x = 4 To 19
.Cells(lRiga, lng).Value = CDbl(Me.Controls(s & lng).Text)
col = col + 1
Next x
'Dico i formati delle Celle
On Error Resume Next
'.Cells(lNuovaRiga, 15).NumberFormat = "#,##0.00"
'.Cells(lNuovaRiga, 16) = CDbl(TextBox12)
End With