Reminder, What is Rounddown
's syntax? From the Microsoft Excel documentation:
ROUNDDOWN(number, num_digits)
- Number – Required. Any real number that you want rounded down.
- Num_digits – Required. The number of digits to which you want to round number.
So in your code the first mistake I saw is here :
Selection.WorksheetFunction.RoundDown (Activecell.Value)
This line must be like below :
Application.WorksheetFunction.RoundDown (Activecell.Value , 0)
So your code would be like that :
Sub Macro1()
Dim Activecell As Range
Dim rounddownvar As Double
Selection.SpecialCells(xlCellTypeVisible).Select
For Each Activecell In Selection
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
rounddownvar = Application.WorksheetFunction.rounddown(Activecell.Value, 1)
Debug.Print rounddownvar
Next Activecell
End Sub
I added Application.WorksheetFunction.rounddown(Activecell.Value, 1)
into a var because this line returns a number ...
Without select to be more efficient :
Sub AvoidingSelect()
Dim rng As Range, cll As Range
Set rng = Range(Range("A2:B2"), Range("A2:B2").End(xlDown)).SpecialCells(xlCellTypeVisible)
Sheets("Sheet1").Range("A1:AA100000").SpecialCells(xlCellTypeVisible).Copy
Sheets("Sheet1").PasteSpecial xlPasteValues
For Each cll In rng
If IsNumeric(cll.Value) Then
Debug.Print Application.WorksheetFunction.RoundDown(cll.Value, 0)
End If
Next
End Sub
CAUTION:
Please respect RoundDown
syntax :
RoundDown(cll.Value, 0) here 0 is the number of digit you want to delete after the , .
For Example :
RoundDown(cll.Value, 0) give : 0.000
RoundDown(cll.Value, 3) give : 0
Working :
Sub AvoidingSelect()
Dim rng As Range, cll As Range
Set rng = Range(Range("G2:G12854"), Range("G2:G12854").End(xlDown)).SpecialCells(xlCellTypeVisible)
Sheets("Sheet1").Range("G2:G12854").SpecialCells(xlCellTypeVisible).Copy
Sheets("Sheet1").Range("G2:G12854").PasteSpecial xlPasteValues
For Each cll In rng
If IsNumeric(cll.Value) Then
Debug.Print cll.Value
cll = Application.WorksheetFunction.RoundDown(cll.Value, 8)
End If
Next
End Sub