Inputbox Displays Wrong percentage In Cell

invblemn

New Member
Joined
Aug 12, 2003
Messages
29
I have an Input Box which prompts the user for a value. The cell which the value will be assigned to is already formatted for percentages. When i enter a numer int he input box the value that is entered into the cell is 100x greater than the value i typed in. for instance i typed in 33 and the cell displayed 3300%. Now if i don't use the macro and type 33 into the cell it displays 33%. the code is pretty strait forward so i'm not sure why this is doing this.

Dim DesignPercentage As String
DesignPercentage = InputBox("Enter Percentage of Total Cost For Design Charge", "Design Percentage", 0)
If DesignPercentage = "" Then Exit Sub
Range("ak22").Value = DesignPercentage

thanks for taking the time to look over my problem.

nick
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Okay. I would use something like this. Instead of assigning to a string, assign to a number.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> GetPercent()
    <SPAN style="color:#00007F">Dim</SPAN> DesignPercentage
    DesignPercentage = Application.InputBox("Enter Percentage of Total Cost <SPAN style="color:#00007F">For</SPAN> Design Charge", _
        "Design Percentage", 0, Type:=1)

    <SPAN style="color:#00007F">If</SPAN> DesignPercentage <> <SPAN style="color:#00007F">False</SPAN> <SPAN style="color:#00007F">Then</SPAN> [A1] = DesignPercentage / 100
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0
thanks tommygun.

I appreciate the help. I have a series of these prompts in one macro. should i replace the the rest of the code with you're version, is there a more simple way of writing the code, or should i just leave it the way it is.? all of the entries ar numerical enties. most are just whole numbers. some are put into cells with currecy format. Do you have any suggestions?

nick
 
Upvote 0
Microsoft Excel VBA Help said:
The InputBox method differs from the InputBox function in that it allows selective validation of the user's input, and it can be used with Microsoft Excel objects, error values, and formulas. Note that Application.InputBox calls the InputBox method; InputBox with no object qualifier calls the InputBox function.

The benefit of using the method as posted above is that you can easily validate the type of entry made in the InputBox. If you place your cursor over any part of the word "InputBox" in the above code (once pasted into VBA), and press F1, you will get a more detailed description fo this method.
 
Upvote 0

Forum statistics

Threads
1,214,967
Messages
6,122,503
Members
449,090
Latest member
RandomExceller01

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