Adding a variable in VBA code

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
771
Office Version
  1. 365
Platform
  1. Windows
I'd like some help with using a variable in VBA for the abbreviated sample code below.

First, I have three macros, listed below. All do different things and work fine.
Sub Feedback_P10()
Sub Feedback_P12()
Sub Feedback_P15()

This following macro checks a cell in row P to see if there is a formula and returns "Yes" in column C in the same row if there is one.
Code:
Sub Formula_P(rowNum As Integer)

Dim rowNumber As Integer
Dim columnNumber As Integer
rowNumber = rowNum

If Range("P" & rowNumber).HasFormula = True Then
Range("C" & rowNumber).Value = "Yes"
End If
End Sub

The code below first calls Formula_P for cell P10.

Sub RESULTS()
Call Formula_P(10)
Call Feedback_P10 Is there a way to make this "10" a variable?
End Sub

Here is what I would like to happen using a variable in the Feedback macro:
If Call Formula_P(10) is in the RESULTS macro, the Feedback_P10() should also be called.
If Call Formula_P(12) is in the RESULTS macro, the Feedback_P12() should also be called.
If Call Formula_P(15) is in the RESULTS macro, the Feedback_P15() should also be called.

Thanks!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Is there any similarity between the various Feedback routines, so that they could be replaced with one routine with a parameter, like the Formula routine? If not, you'd need to use something like Application.Run
 
Upvote 0
Feedback routines are all different, so I'm not able to handle it like the Formula routine.

Application.run?

Thanks.
 
Upvote 0
Yup. :)

VBA Code:
Application.Run "FeedbackP" & variable

Or since you only have three options, you could use a simple If block or a select case statement.
 
Upvote 0
Solution
There are actually more than three options in the project - I only posted a short sample.

However, your response about an If block made me see an alternative way of dealing with this, and it is working!

Thanks so much for your response - very helpful! CJ
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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