
Sub MediaFiltrata()
'Esegue la media sulla colonna eliminando i primi e gli ultimi dieci valori
Dim ws As Worksheet
Dim rng As Range
Dim cella As Range
Dim nCol As Long
Dim nRow As Long
Set ws = ActiveSheet
With ws
Set rng = Intersect(.Columns(8), .Cells(1, 1).SpecialCells(xlCellTypeFormulas, 1))
nRow = 3
For Each cella In rng.Areas
Set cella = cella.Resize(cella.Rows.Count - 20).Offset(10)
.Cells(nRow, 10).Value = Application.Average(cella) ' media da riga 3
nRow = nRow + 1
Next
End With
Set ws = Nothing
Set rng = Nothing
End Sub
|
h t t p s :// docs.google.com/file/d/0B5TqB-Y8jMqMYzlkRWdtV0xBYlU/edit?usp=sharing |
... ultimariga = Cells(Rows.Count, 8).End(xlUp).Row For x = 3 To ultimariga If Cells(x, 8) = "" Then If x - 10 >= 3 Then Cells(x, 9) = Application.Average(Range(Cells(x - 10, 8), Cells(x + 10, 8))) End If End If Next ... |
Sub MediaFiltrata2()
'Esegue la media sulla colonna eliminando i primi e gli ultimi dieci valori
Dim ws As Worksheet
Dim rng As Range
Dim cella As Range
Dim nCol As Long
Dim nRow As Long
Set ws = ActiveSheet
With ws
Set rng = Intersect(.Columns(8), .Cells(1, 1).SpecialCells(xlCellTypeFormulas, 1))
nRow = 3
For Each cella In rng.Areas
If cella > 30 Then 'Vorrei che eseguisse il seguente codice solo se il range trovato è maggiore di 30 celle
Set cella = cella.Resize(cella.Rows.Count - 20).Offset(10)
.Cells(nRow, 10).Value = Application.Average(cella)
nRow = nRow + 1
Else 'Se il range trovato è < di 30 non fare nulla
End If 'fine dell'If
Next
End With
Set ws = Nothing
Set rng = Nothing
End Sub |
Sub trovaVuote2()
Dim Area1 As Range, Area2 As Range
Dim Vuota1, Vuota2, QuanteVuote, Riga1, Riga2, Righe
Vuota1 = 2
Riga1 = Vuota1 + 1
ultimariga = Cells(Rows.Count, 8).End(xlUp).Row
Set Area1 = Range(Cells(Riga1, 8), Cells(ultimariga + 1, 8))
QuanteVuote = Application.WorksheetFunction.CountIf(Area1, "")
For Y = 1 To QuanteVuote
Set Area1 = Range(Cells(Riga1, 8), Cells(ultimariga + 1, 8))
Set Vuota2 = Area1.Find("", LookIn:=xlValues, LookAt:=xlWhole)
If Vuota2 Is Nothing Then
Else
Riga2 = Vuota2.Row - 1
Righe = Riga2 - Riga1 + 1
If Righe >= 30 Then
MsgBox ("Trovati " & Righe & " righe di dati dalla " & Riga1 & " alla " & Riga2)
Cells(Riga2 + 1, 9) = Application.Average(Range(Cells(Riga1, 8), Cells(Riga2, 8)))
'Cells(Riga2 + 1, 9) = Application.Average(Range(Cells(Riga1 +10, 8), Cells(Riga2 -10, 8)))
End If
End If
Riga1 = Riga2 + 2
Next Y
End Sub |
If Righe >= 30 Then Cells(Riga2 + 1, 9) = Application.Average(Range(Cells(Riga1 +10, 8), Cells(Riga2 -10, 8))) else Cells(Riga2 + 1, 10) = Application.Average(Range(Cells(Riga1, 8), Cells(Riga2, 8))) End If |
Sub MediaRange()
Dim Area1 As Range, Area2 As Range
Dim Vuota1, Vuota2, QuanteVuote, Riga1, Riga2, Righe
Dim nRow
Vuota1 = 1
Riga1 = Vuota1 + 2
ultimariga = Cells(Rows.Count, 8).End(xlUp).Row
Set Area1 = Range(Cells(Riga1, 8), Cells(ultimariga + 1, 8))
'QuanteVuote = Application.WorksheetFunction.CountIf(Area1, "")
For Y = 3 To ultimariga
Set Area1 = Range(Cells(Riga1, 8), Cells(ultimariga + 1, 8))
Set Vuota2 = Area1.Find("", LookIn:=xlValues, LookAt:=xlWhole)
If Vuota2 Is Nothing Then
Else
Riga2 = Vuota2.Row - 1
Righe = Riga2 - Riga1 + 1
nRow = 3
If Righe >= 30 Then
'Cells(nRow, 11) = Application.Average(Range(Cells(Riga1, 8), Cells(Riga2, 8)))
Cells(nRow, 11) = Application.Average(Range(Cells(Riga1 + 10, 8), Cells(Riga2 - 10, 8)))
nRow = nRow + 1
End If
End If
Riga1 = Riga2 + 2
Next Y
End Sub |
Sub trovaVuote3()
Dim Area1 As Range, Area2 As Range, Area3 As Range, Area4 As Range, Area5 As Range, cella As Range
Dim Vuota1, Vuota2, QuanteVuote, Riga1, Riga2, Righe, riga
Vuota1 = 2
Riga1 = Vuota1 + 1
ultimariga = Cells(Rows.Count, 8).End(xlUp).Row
Set Area1 = Range(Cells(Riga1, 8), Cells(ultimariga, 8))
QuanteVuote = Application.WorksheetFunction.CountIf(Area1, "")
For Y = 1 To QuanteVuote
Set Area1 = Range(Cells(Riga1, 8), Cells(ultimariga + 1, 8))
Set Vuota2 = Area1.Find("", LookIn:=xlValues, LookAt:=xlWhole)
If Vuota2 Is Nothing Then
Else
Riga2 = Vuota2.Row - 1
Righe = Riga2 - Riga1 + 1
If Righe >= 30 Then
Set Area3 = Range(Cells(Riga1, 8), Cells(Riga1 + 9, 8))
Set Area4 = Range(Cells(Riga1 + 10, 8), Cells(Riga2 - 10, 8))
Set Area5 = Range(Cells(Riga2 - 9, 8), Cells(Riga2, 8))
For Each cella In Area3
cella.Activate
riga = Selection.Row
Cells(riga, 11).Value = Application.Average(Range(Cells(Riga1, 8), Cells(riga + 10, 8)))
Next cella
For Each cella In Area4
cella.Activate
riga = Selection.Row
Cells(riga, 10).Value = Application.Average(Range(Cells(riga - 10, 8), Cells(riga + 10, 8)))
Next cella
For Each cella In Area5
cella.Activate
riga = Selection.Row
Cells(riga, 11).Value = Application.Average(Range(Cells(riga - 10, 8), Cells(Riga2, 8)))
Next cella
End If
End If
Riga1 = Riga2 + 2
Next Y
MsgBox ("Fatto")
End Sub |
Sub MediaFiltrata()
'Esegue la media sulla colonna eliminando i primi e gli ultimi dieci valori
Dim ws As Worksheet
Dim rng As Range
Dim cella As Range
Dim nCol As Long
Dim nRow As Long
Set ws = ActiveSheet
With ws
Set rng = Intersect(.Columns(8), .Cells(1, 1).SpecialCells(xlCellTypeFormulas, 1))
nRow = 3
For Each cella In rng.Areas
If cella.Rows.Count > 30 Then
Set cella = cella.Resize(cella.Rows.Count - 20).Offset(10)
.Cells(nRow, 10).Value = Application.Average(cella) ' media da riga 3
nRow = nRow + 1
Else
End If
Next
End With
Set ws = Nothing
Set rng = Nothing
End Sub |
