Always room for improvement

swaink

Active Member
Joined
Feb 15, 2002
Messages
432
Hi All

I have reached a small hitch with using VBA to carry out a calulation.

In Cell D8 I have a date field and anchor my vba on that cell and use offset to achieve what I am aiming for.

All works well except for a percentage calulation when I divide cell D10 by D9 and place the value in cell D14 ("ActiveCell.Offset(6, 0).Value")

This is the line I use to do the calulation and I expect to see a percentage value such as 98.3 % but the end result shows as 9.893129770992370.00% and I can't see why

ActiveCell.Offset(6, 0).Value = (ActiveCell.Offset(2, 0).Value / ActiveCell.Offset(1, 0).Value) * 10 & Format("0.0", "Percent")

All advice appreciated

Kevin
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
First it is not generally necessary to Select or Activate cells you can work with ranges directly in VBA.

I'm assuming that in D9 and D10 you have values like 98.3, which you then want to show as a percent:

Code:
Sub test()
With Range("D14")
    .NumberFormat = "0.00%"
    .Value = (Range("D10") / Range("D9")) / 100
End With
End Sub
 
Upvote 0
Hi Hotpepper

Thanks for the quick responce and it certainly looks cleaner than my approach.

I have applied this but the result is now showing as 0.989% is there a way to make this look like 98.9% or am I doing something wrong

Kev
 
Upvote 0
Thats cracked it Hotpepper

Many thanks for your time I do appreciate it and I have learned something new in the process

Kevin
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,151
Members
452,891
Latest member
JUSTOUTOFMYREACH

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