I need help with this part Cells(y + Z).Value, can anyone tell me what I did wrong...

MartinLe50

New Member
Joined
Aug 28, 2020
Messages
7
Office Version
  1. 2016
Platform
  1. 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
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You're missing a row number for the Range("x") and Range("Y") parts.

I'm not clear what you think Cells(X + Y) means? Cells needs a row and column number as separate arguments, as in your earlier code.
 
Upvote 0
It would probably help if you explain what you are trying to do, rather than posting code that doesn't make any sense. ;)
 
Upvote 0
I want to make a change to the price displayed in the grey columns before we multiply it by 2. If the price is < 17.50 such as 17.34 or 17.49 I want it to be flat 17.00. But, if the price is 17.50 or above I watch the price to be fixed 17.50. The same goes for every number not just "seventeen" of course.
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top