Need Assistance using VBA Select Case to make a Piecewise graph

extrahotfudge

New Member
Joined
Apr 9, 2021
Messages
10
Office Version
  1. 365
  2. 2019
Platform
  1. MacOS
Hello! I am needing assistance on the code for Select Case in VBA. I have a column of Integers, x, and want to use the Select case to find their value in a piecwise function.
1617986179816.png


I'm not very skilled with VBA or Macros, so I did some research and this is what I came up with:

Function Calc(x)
Select Case x
Case Is < 0
x^ 3
Case 0 To 3
x^ 2
Case Is > 3
Sqr (x - 3)

End Select
End Function

But it returns an error when I try to apply it to my x cell.

I am lost, please help, thanks!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Welcome to the forum!

Excel Formula:
Function Calc(x)
  Dim y
  Select Case x
    Case Is < 0
      y = x ^ 3
    Case 0 To 3
      y = x ^ 2
    Case Is > 3
      y = Sqr(x - 3)
    Case Else
  End Select
  Calc = y
End Function
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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