
Public Sub prova()
Dim j As Long
Dim sRow As String
Dim aRow As Variant
Dim vRow
For j = 1 To 65536
sRow = sRow & j & " "
Next
aRow = Split(Trim(sRow))
With Application
vRow = .Transpose(aRow) <---- no problem
Debug.Print UBound(vRow)
ReDim Preserve aRow(0 To 65537)
vRow = .Transpose(aRow) '<--- ERRORE
Debug.Print UBound(vRow)
End With
End Sub
|
Sub MACRO1()
'
'
'
Application.ScreenUpdating = False
Dim nStart As Single
nStart = Timer
Sheets("Foglio1").Columns("A:E").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Foglio1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Foglio1").Sort.SortFields.Add Key:=Columns("B:B") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Foglio1").Sort.SortFields.Add Key:=Columns("A:A") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Foglio1").Sort
.SetRange Columns("A:E")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Dim ws1 As Worksheet, ws2 As Worksheet
Dim rng1 As Range, cella As Range
Dim vArr As Variant, sRow As String, nLR As Long
Set ws1 = Sheets("Foglio1")
Set ws2 = Sheets("Foglio2")
nLR = ws1.Cells(Rows.Count, 6).End(xlUp).Row
Set rng1 = ws1.Range("F1:F" & nLR)
For Each cella In rng1
If cella.Value = "OK" Then sRow = sRow & " " & cella.Row
Next
sRow = Trim(sRow)
With Application
vArr = .Index(ws1.Columns("A:E"), .Transpose(Split(sRow)), Array(1, 2, 3, 4, 5))
End With
nLR = ws2.Cells(Rows.Count, 1).End(xlUp).Row
ws2.Range("A" & nLR + 1 & ":E" & UBound(vArr) + nLR) = vArr
Set rng1 = Nothing
Set ws1 = Nothing
Set ws2 = Nothing
Application.ScreenUpdating = True
MsgBox "Elaborazione eseguita in " & Timer - nStart
End Sub
|
Sub MACRO1()
'
'
'
Dim ws1 As Worksheet, ws2 As Worksheet
Dim rng1 As Range, cella As Range
Dim vArr As Variant, sRow As String, nLR As Long
Dim nStart As Single
Dim nOK As Long
Dim aOK(1 To 100) As String
Dim j As Integer
Application.ScreenUpdating = False
nStart = Timer
Set ws1 = Sheets("Foglio1")
Set ws2 = Sheets("Foglio2")
With ws1.Sort
.SortFields.Clear
.SortFields.Add Key:=Columns("B:B") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Columns("A:A") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Columns("A:E")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
nLR = ws1.Cells(Rows.Count, 6).End(xlUp).Row
Set rng1 = ws1.Range("F1:F" & nLR)
nOK = 0
j = 1
For Each cella In rng1
If cella.Value = "OK" Then
nOK = nOK + 1
j = (nOK 65000) + 1
aOK(j) = aOK(j) & " " & cella.Row
End If
Next cella
For j = 1 To 100
sRow = Trim(aOK(j))
If sRow = "" Then Exit For
With Application
vArr = .Index(ws1.Columns("A:E"), .Transpose(Split(sRow)), Array(1, 2, 3, 4, 5))
End With
nLR = ws2.Cells(Rows.Count, 1).End(xlUp).Row
ws2.Range("A" & nLR + 1 & ":E" & UBound(vArr) + nLR) = vArr
Next j
Set rng1 = Nothing
Set ws1 = Nothing
Set ws2 = Nothing
Application.ScreenUpdating = True
MsgBox "Elaborazione eseguita in " & Timer - nStart
End Sub
|
Sub Ricerca()
Dim Via As Variant, Tot As Variant
Dim Msec As Variant
Via = GetTickCount
Tot = Via
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.StatusBar = False
Application.EnableCancelKey = xlDisabled
ActiveWindow.View = xlNormalView
ActiveSheet.PageSetup.PrintArea = ""
ActiveSheet.DisplayPageBreaks = False
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim e As String
Dim x As String
Dim LastRow As Long
Sheets("Foglio2").Cells.ClearContents 'cancello tutti i dati di questo foglio
With Range("F1:F" & Range("F" & Rows.Count).End(xlUp).Row)
a = .Offset(, -5).Address
b = .Offset(, -4).Address
c = .Offset(, -3).Address
d = .Offset(, -2).Address
e = .Offset(, -1).Address
x = .Address
With Worksheets("Foglio2").Range("F1:F" & Range("F" & Rows.Count).End(xlUp).Row)
.Offset(1, -5) = Evaluate("if(EXACT(" & x & ",""OK"")," & a & ","""")")
.Offset(1, -4) = Evaluate("if(EXACT(" & x & ",""OK"")," & b & ","""")")
.Offset(1, -3) = Evaluate("if(EXACT(" & x & ",""OK"")," & c & ","""")")
.Offset(1, -2) = Evaluate("if(EXACT(" & x & ",""OK"")," & d & ","""")")
.Offset(1, -1) = Evaluate("if(EXACT(" & x & ",""OK"")," & e & ","""")")
End With
End With
Sheets("Foglio2").Select
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
ActiveWorkbook.Worksheets("Foglio2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Foglio2").Sort.SortFields.Add Key:=Range("A2:A" & LastRow) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Foglio2").Sort
.SetRange Range("A2:E" & LastRow)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.StatusBar = True
Application.ScreenUpdating = True
Msec = GetTickCount - Via
MsgBox Format$(Msec 3600000, "00") & ":" & Format$(((Msec - (Msec 3600000) * 3600000)) 60000, "00") & ":" & Format$((Msec - (Msec 60000) * 60000) / 1000, "00.000")
End Sub
|
Option Explicit Private Declare Function GetTickCount Lib "kernel32" () As Long |
Sub MACRO1()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim rng1 As Range
Dim nStart As Single
Dim bCalc As XlCalculation
With Application
bCalc = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
nStart = Timer
Set ws1 = Sheets("Foglio1")
Set ws2 = Sheets("Foglio2")
With ws1.Sort
.SortFields.Clear
.SortFields.Add Key:=Columns("B:B") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Columns("A:A") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Columns("A:E")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
nLR = ws1.Cells(Rows.Count, 6).End(xlUp).Row
Set rng1 = ws1.Range("A1:F" & nLR)
rng1.AutoFilter
rng1.AutoFilter Field:=6, Criteria1:="=OK", _
Operator:=xlAnd
rng1.SpecialCells(xlCellTypeVisible).Copy
With ws2
.Activate
.Range("A2").PasteSpecial xlPasteValues
.Range("A2").PasteSpecial xlPasteFormats
If .Range("F2").Value <> "OK" Then .Range("A2:F2").Delete xlShiftUp
.Columns(6).Clear
End With
ws1.Activate
rng1.AutoFilter
Set rng1 = Nothing
Set ws1 = Nothing
Set ws2 = Nothing
With Application
.Calculation = bCalc
.ScreenUpdating = True
End With
MsgBox "Elaborazione eseguita in " & Timer - nStart
End Sub
|
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.StatusBar = False
Application.EnableCancelKey = xlDisabled
ActiveWindow.View = xlNormalView
ActiveSheet.PageSetup.PrintArea = ""
ActiveSheet.DisplayPageBreaks = False
|
Sub MACRO1BIS()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim rng1 As Range
Dim nStart As Single
Dim bCalc As XlCalculation
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.StatusBar = False
Application.EnableCancelKey = xlDisabled
ActiveWindow.View = xlNormalView
ActiveSheet.PageSetup.PrintArea = ""
ActiveSheet.DisplayPageBreaks = False
With Application
bCalc = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
nStart = Timer
Set ws1 = Sheets("Foglio1")
Set ws2 = Sheets("Foglio2")
With ws1.Sort
.SortFields.Clear
.SortFields.Add Key:=Columns("B:B") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Columns("A:A") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Columns("A:E")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
nLR = ws1.Cells(Rows.Count, 6).End(xlUp).Row
Set rng1 = ws1.Range("A1:F" & nLR)
rng1.AutoFilter
rng1.AutoFilter Field:=6, Criteria1:="=OK", _
Operator:=xlAnd
rng1.SpecialCells(xlCellTypeVisible).Copy
With ws2
.Activate
.Range("A2").PasteSpecial xlPasteValues
.Range("A2").PasteSpecial xlPasteFormats
If .Range("F2").Value <> "OK" Then .Range("A2:F2").Delete xlShiftUp
.Columns(6).Clear
End With
ws1.Activate
rng1.AutoFilter
Set rng1 = Nothing
Set ws1 = Nothing
Set ws2 = Nothing
With Application
.Calculation = bCalc
.ScreenUpdating = True
End With
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.StatusBar = True
Application.ScreenUpdating = True
MsgBox "Elaborazione eseguita in " & Timer - nStart
End Sub
|
Sub Test2()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim rng As Range, cella As Range
Dim vArr As Variant, sRow As String, nLR As Long
Dim nStart As Single
nStart = Timer
Set ws1 = Foglio1
Set ws2 = Foglio2
nLR = ws1.Cells(Rows.Count, 5).End(xlUp).Row
Set rng = ws1.Range("E2:E" & nLR)
nLR = ws2.Cells(Rows.Count, 1).End(xlUp).Row + 1
Intersect(rng.SpecialCells(xlCellTypeConstants, 2).EntireRow, ws1.Range("A:D")).Copy Destination:=ws2.Range("A" & nLR)
Set rng = Nothing
Set ws1 = Nothing
Set ws2 = Nothing
MsgBox "Tabella copiata in " & Timer - nStart
End Sub |
Sub Test2()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim rng As Range, cella As Range
Dim vArr As Variant, sRow As String, nLR As Long
Dim nStart As Single
nStart = Timer
Set ws1 = Foglio1
Set ws2 = Foglio2
nLR = ws1.Cells(Rows.Count, 6).End(xlUp).Row
Set rng = ws1.Range("F2:F" & nLR)
nLR = ws2.Cells(Rows.Count, 1).End(xlUp).Row + 1
Intersect(rng.SpecialCells(xlCellTypeConstants, 2).EntireRow, ws1.Range("A:E")).Copy Destination:=ws2.Range("A" & nLR)
Set rng = Nothing
Set ws1 = Nothing
Set ws2 = Nothing
MsgBox "Tabella copiata in " & Timer - nStart
End Sub |
