
Dim Righe, Colonne, R, C
Dim Intervallo As Range
With Range("A1").CurrentRegion
Righe = .Rows.Count - 1
Colonne = .Columns.Count
Set Intervallo = .Offset(1, 0).Resize(Righe, Colonne)
End With
With ListBox1
.Clear
.ColumnCount = Colonne
.BoundColumn = 2
For R = 1 To Righe
.AddItem
For C = 1 To Colonne
.List(R - 1, C - 1) = Intervallo(R, C)
Next
Next
End With |
Private Sub Combobox1_change()
Dim Data As Date
If ComboBox2.Value = "" Then Exit Sub
Data1 = CDate("1/" & ComboBox2.Value & "/" & ComboBox1.Value)
Data2 = DateSerial(Year(Data1), Month(Data1) + 1, 0)
Dim Righe, R, C
Dim Intervallo As Range
Righe = Range("A" & Rows.Count).End(xlUp).Row
C = 2
With Range("A1").CurrentRegion
Set Intervallo = .Offset(1, 0).Resize(Righe, C)
End With
With ListBox1
.Clear
For R = 2 To Righe
If Cells(R, 2) >= Data1 And Cells(R, 2) <= Data2 Then
.AddItem
.List(R - 1, C - 1) = Intervallo(R, C)
End If
Next
End With
End Sub |
'Public Data
Private Sub UserForm_activate()
'Me.ComboBox1.Value = Year(Date)
'Me.ComboBox2.Value = Format(Month(Date), "mmmm")
End Sub
Private Sub Combobox1_change()
Dim dtData As Date, dtData1 As Date, dtData2 As Date
If ComboBox2.Value = "" Then Exit Sub
dtData1 = CDate("1/" & ComboBox2.Value & "/" & ComboBox1.Value)
dtData2 = DateSerial(Year(dtData1), Month(dtData1) + 1, 0)
Dim Righe, R, C
Dim Intervallo As Range
Righe = Range("A" & Rows.Count).End(xlUp).Row
C = 2
With Range("A1").CurrentRegion
Set Intervallo = .Offset(1, 0).Resize(Righe, C)
End With
With ListBox1
.RowSource = "" '.Clear
For R = 2 To Righe
If Cells(R, 2) >= dtData2 And Cells(R, 2) <= dtData2 Then
.AddItem
.List(R - 1, C - 1) = Intervallo(R, C)
End If
Next
End With
End Sub
Private Sub ComboBox2_change()
Dim dtData As Date
If ComboBox1 = "" Then Exit Sub
dtData = CDate("1/" & ComboBox2 & "/" & ComboBox1)
'Call Trova
Dim Righe, Colonne, R, C
Dim Intervallo As Range
With Range("AD1").CurrentRegion
Righe = .Rows.Count - 1
Colonne = .Columns.Count
Set Intervallo = .Offset(1, 0).Resize(Righe, Colonne)
End With
With ListBox1
.RowSource = ""
.ColumnCount = Colonne
'.BoundColumn = 2
.RowSource = Intervallo.Address
'For R = 1 To Righe
'.AddItem
'For C = 1 To Colonne
'.List(R - 1, C - 1) = Intervallo(R, C)
'Next
'Next
End With
End Sub
'riassunto per la sub trova:
Option Explicit
Sub Trova()
Dim Data As Date, Data1 As Date, Data2 As Date
Data1 = CDate("1/7/2013")
Data2 = DateSerial(Year(Data1), Month(Data1) + 1, 0)
Dim Righe, R, C
Righe = Range("A" & Rows.Count).End(xlUp).Row
C = 2
Range("AD1:AE1000").ClearContents
For R = 2 To Righe
If Cells(R, 2) >= Data1 And Cells(R, 2) <= Data2 Then
Range(Cells(R, 1), Cells(R, 5)).Copy Range("AD" & C & ":AH" & C)
C = C + 1
End If
Next
End Sub |
Private Sub Combobox1_change()
Dim cl As Object
Dim dtData1 As Date, dtData2 As Date
If ComboBox2.Value = "" Then Exit Sub
dtData1 = CDate("1/" & ComboBox2.Value & "/" & ComboBox1.Value)
dtData2 = DateSerial(Year(dtData1), Month(dtData1) + 1, 0)
Dim Righe, R, C
Dim Intervallo As Range
Righe = Range("A" & Rows.Count).End(xlUp).Row
Set Intervallo = Range(Cells(2, 2), Cells(Righe, 2))
ListBox1.Clear
For Each cl In Intervallo
If cl >= dtData1 And cl <= dtData2 Then
ListBox1.AddItem cl.Offset(0, -1)
End If
Next
Set Intervallo = Nothing
End Sub |
