excel - Format to percent with 10 or a lot of decimals in vba -


i've got tricky problem , don't understand happening , why.

i have userform lot of percentage values.

enter image description here

these values come excel sheet, this. user can change these values , put them in excel sheet. user's activity gets saved in log sheet. values saved there well. put values there this:

private sub savev_click()     dim wslog worksheet     dim long     dim j long     dim lastrow long     dim tbnr string     j = 3     = 2     set wslog = thisworkbook.worksheets("log")     wslog         lastrow = findlastrow(wslog)         lastcolumn = findlastcolumn(wslog)         each tb in me.controls             if typename(tb) = "textbox"                 select case                     'case 2 , 3 values fixed , not of interest                     case 2                         .cells(lastrow + 1, 1).value = tb.value                     case 3                         .cells(lastrow + 1, 2).value = tb.value                     'the following cases refer textboxes can see in other picture (there more)                     case 4 46                         .cells(lastrow + 1, j).value = tb.value                     case 47 89                         .cells(lastrow + 2, j).value = format(tb.value, "0.00%")                     case 90 132                         .cells(lastrow + 3, j).value = format(tb.value, "0.00%")                 end select             = + 1             j = j + 1             if j > lastcolumn j = 3             end if         next     end     unload me end sub 

the code runs fine in itself, doesn't format values right.

if use format(tb.value, "0.00%") values rounded 101,49316739% turns 101,49%

i tried adding more zeros, if use format(tb.value, "0.000%") value get's multiplied 1000 turns 101493%. (even more more zeros)

how can save values ten (or more) decimals?

the format function converts value string. means code here...

.cells(lastrow + 2, j).value = format(tb.value, "0.00%") 

...will take double value of 101,49316739 , convert string value of "101,49%". data type of .cells(lastrow + 2, j).value variant, you're giving variant of subtype string. excel has determine if value you're writing can represented number. remember, format displaying readable version of number - not storing values.

just let excel formatting:

.cells(lastrow + 2, j).value = cdbl(tb.value) \ 100    'cast string double , scale. .cells(lastrow + 2, j).numberformat = "0.000000000000000%"    'format cell. 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -