Variable value changing for no reason

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I'm passing values from one Excel sheet to others, it turns out that the variable P666_2 has the value "xxx.xxxx" but when the value is passed to the other sheet the value is in the format "xxxxxxx,0000", can someone help me solve it this problem?


VBA Code:
 Sheets("Calculation_Sheet").Visible = True
    ActiveWorkbook.Sheets("calculation_sheet").Activate

    Cells(18, 2).Value = A_90
    Cells(26, 2).Value = A0
    Cells(33, 2).Value = A90
    
    oPL = Format(Cells(6, 9), "0.####")
    o709 = Format(Cells(7, 9), "0.####")
    o710 = Format(Cells(8, 9), "0.####")
    o713 = Format(Cells(9, 9), "0.####")

    P666_2 = Format(Cells(6, 10), "0.####")
    P709_2 = Format(Cells(7, 10), "0.####")
    P710_2 = Format(Cells(8, 10), "0.####")
    P713_2 = Format(Cells(9, 10), "0.####")

    out_666.Value = P666_2
    out_709.Value = P709_2
    out_710.Value = P710_2
    out_713.Value = P713_2
    out_Spread2.Value = Delta_A
    
    Cells(6, 9).Value = P666_2
    
    MsgBox "P666_2 =" & P666_2
    MsgBox "Cells(6, 9) =" & Cells(6, 9).Value

1.JPG


2.JPG
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
It's not a variable error.....You need to change the format of cells(6,9)
 
Upvote 0
Rclik on the cell...format cells..choose the number format
 
Upvote 0
Don't use Format when assigning the values to the variables.
 
Upvote 0
Unless I am mistaken the Format function isn't doing anything for you except possible truncating any decimals beyond the 4 digits.
All you end up doing is converting the value to text and its then converting back to a number when you put is in a cell.
Is your original value text or a number
What is the original value ?
Also I take it the decimal marker in your region is a comma, what is the thousands separator marker ?
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

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