Variables

Deepjuillet

New Member
Joined
May 21, 2022
Messages
1
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Hi I have an excel sheet that names a number of cells as variables. For example cell A1 is defined as speed and in formulas elsewhere in the workbook I have used speed in formulas rather than A1.

I now want to write a function in VBA that uses speed in a formula. Rather than referring to A1, I want to know if I can use the named variable (speed) in the module. When I wrote the code and ran debugger it showed no error but returned zero as result.

Is this possible? I can always to the calculations in the workbook itself but thought I’d try developing a function and use that instead.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
This is just a very simple example for cell A1 defined as speed, if you need a Function it wouldn't be much different.
VBA Code:
Sub test()
    Range("B1") = Range("speed") * 250
    Range("B2").FormulaR1C1 = "=speed*250"
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,228
Messages
6,129,614
Members
449,520
Latest member
TBFrieds

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