ChristineJ
Well-known Member
- Joined
- May 18, 2009
- Messages
- 771
- Office Version
- 365
- Platform
- Windows
The variables in the code below count occurrences of different strings that appear within the formula in cell P10. (The list is much longer; this is just a sample.)
The variables countCell1, countCell2, countFunc6, countFunc12, countChar4, and countChar8 are Public Const in a different module, such as Public Const itemCell1 As String = "D9"
I need to use these same variables for six more macros in the same module - Sub Feedback_P11(), Sub Feedback_P12(), etc.
Right now I am recopying all of these same variables into each of the six additional macros, so there is a lot of redundancy.
I tried declaring and listing the variables at the top of the module above the macros, but it is not working. Sample:
Could this be adapted so I can declare all of these variables just once and them use them, as needed, in different macros in the same module?
Thanks for the help! C
The variables countCell1, countCell2, countFunc6, countFunc12, countChar4, and countChar8 are Public Const in a different module, such as Public Const itemCell1 As String = "D9"
I need to use these same variables for six more macros in the same module - Sub Feedback_P11(), Sub Feedback_P12(), etc.
Code:
Sub Feedback_P10()
myTxt = Range("P10").Formula
countCell1 = (Len(myTxt) - Len(Replace(myTxt, itemCell1, ""))) / Len(itemCell1)
countCell2 = (Len(myTxt) - Len(Replace(myTxt, itemCell2, ""))) / Len(itemCell2)
countFunc6 = (Len(myTxt) - Len(Replace(myTxt, itemFunc6, ""))) / Len(itemFunc6)
countFunc12 = (Len(myTxt) - Len(Replace(myTxt, itemFunc12, ""))) / Len(itemFunc12)
countChar4 = (Len(myTxt) - Len(Replace(myTxt, itemChar4, ""))) / Len(itemChar4)
countChar8 = (Len(myTxt) - Len(Replace(myTxt, itemChar8, ""))) / Len(itemChar8)
countEndD = (Len(myTxt) - Len(Replace(myTxt, "D(", ""))) / Len("D(")
countEndM = (Len(myTxt) - Len(Replace(myTxt, "M(", ""))) / Len("M(")
countEndN = (Len(myTxt) - Len(Replace(myTxt, "N(", ""))) / Len("N(")
countEndR = (Len(myTxt) - Len(Replace(myTxt, "R(", ""))) / Len("R(")
countEndS = (Len(myTxt) - Len(Replace(myTxt, "S(", ""))) / Len("S(")
TotalP10 = countEndD + countEndM + countEndN + countEndR + countEndS
ResultP10 = countCell1 + count Func12 + TotalP10
Right now I am recopying all of these same variables into each of the six additional macros, so there is a lot of redundancy.
I tried declaring and listing the variables at the top of the module above the macros, but it is not working. Sample:
Code:
Dim myTxt As String
Dim countCell1 As Integer
Dim countCell2 As Integer
countCell1 = (Len(myTxt) - Len(Replace(myTxt, itemCell1, ""))) / Len(itemCell1)
countCell2 = (Len(myTxt) - Len(Replace(myTxt, itemCell2, ""))) / Len(itemCell2)
Could this be adapted so I can declare all of these variables just once and them use them, as needed, in different macros in the same module?
Thanks for the help! C