LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Add to a variable via a function

I have a situation whereby I want to count the number of records and place
the number in different variables based on two different cells in the record.
The following is a snippet of the hopefully streamlined code. This will
eleviate a lot of duplicate code by putting the If|Else Statements in a sub
routine and and passing some information to that sub and have it count and
put the count in the variable. But I have to build the name of the variable
in the sub and then get them to reference the actual variables... is this
possible?

Dim Type1var1, Type2var2, Type3var3 as integer 'in General Declarations


sub Populate
For Each cell In Range("List")
status = cell.Offset(0, 5)

Select Case cell.Offset(0, 27)
'Type1
Case 888, 889
Call CalcOrig("Type1", status)
'Type2
Case 893, 894
Call CalcOrig("Type2", status)
Case 900 to 905
Call CalcOrig("Type3",status)
End Select

Next
end sub

sub CalcOrig(prefix as string, status as string)
If status = "Accepted" Or _
status = "Approved - override" Or _
status = "Auto-Approve" Then
newvar = prefix & "var1" ' I want this to reference the variable
' Type1var1... IS THIS
POSSIBLE?
newvar = newvar + 1

ElseIf status = "Approved-Counteroffer" _
Or status = "Qualified-Workout" Then
newvar = prefix & "var2" ' I want this to reference the variable
' Type1var2... IS THIS
POSSIBLE?
newvar = newvar + 1

ElseIf status = "Declined" Or _
status = "Declined - override" Then
newvar = prefix & "var3" ' I want this to reference the variable
' Type1var3... IS THIS
POSSIBLE?
newvar = newvar + 1
End If

end sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable Value Function Help? Jonathan Cheek[_2_] Excel Worksheet Functions 2 December 22nd 09 05:33 AM
Variable Sum Function David G. Excel Discussion (Misc queries) 9 December 29th 08 08:34 PM
Variable function ESP Tom Excel Discussion (Misc queries) 0 July 10th 06 02:15 PM
using a variable in a function alvin Kuiper Excel Programming 2 February 9th 06 04:58 AM
Set variable to a function Dan Excel Programming 3 June 11th 04 03:09 PM


All times are GMT +1. The time now is 08:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"