MartinLe50
New Member
- Joined
- Aug 28, 2020
- Messages
- 7
- Office Version
- 2016
- Platform
- Windows
I am 2 weeks in learning VBA and need some help how to structure this code...
Sub Return_only_decimal_part_of_a_number()
'declare a variable
Dim x As Double
Dim i As Double
Dim j As Double
Dim y As Range
Dim ws As Worksheet
Set ws = Worksheets("Dashboard T.1-T.3")
For i = 3 To 49
For j = 3 To 67 Step 2
y = Cells(i, j).Value
'return only the decimal part of a number that is captured in a specific cell
ws.Range("x") = ws.Range("y") - Fix(ws.Range("y"))
g = ws.Range("x")
Z = 0.5
If g < 0.5 Then
Cells(y + Z).Value
Else: Cell.Values = WorksheetFunction.RoundDown(y, 2)
End If
Next j
Next i
End Sub
Sub Return_only_decimal_part_of_a_number()
'declare a variable
Dim x As Double
Dim i As Double
Dim j As Double
Dim y As Range
Dim ws As Worksheet
Set ws = Worksheets("Dashboard T.1-T.3")
For i = 3 To 49
For j = 3 To 67 Step 2
y = Cells(i, j).Value
'return only the decimal part of a number that is captured in a specific cell
ws.Range("x") = ws.Range("y") - Fix(ws.Range("y"))
g = ws.Range("x")
Z = 0.5
If g < 0.5 Then
Cells(y + Z).Value
Else: Cell.Values = WorksheetFunction.RoundDown(y, 2)
End If
Next j
Next i
End Sub