ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Better way to write this VBA (https://www.excelbanter.com/excel-programming/278275-better-way-write-vba.html)

Heather[_5_]

Better way to write this VBA
 
Is there a better way to choose the variables that I want?
Here's what I have so far and I need to expand it to 6
different choices rather than 3
'MemberInfo data for the GroupID
If ClassVar1 = "" And ClassVar2 = "" And ClassVar3 = "" _
And PlanVar1 = "" And PlanVar2 = "" And PlanVar3 = "" _
And BusVar1 = "" And BusVar2 = "" And BusVar3 = "" _
Then

strSQL = "Select SaCd, count(MemId)" & _
"From MemberInfoFacets " & _
"Where GroupID IN ('" & GroupVar1 & "','" &
GroupVar2 & "', '" & GroupVar3 & "') " & _
" AND MemDate = " & INDV & _
" GROUP BY SaCd"

'MemberInfo data for the GroupID and ClassID
ElseIf PlanVar1 = "" And PlanVar2 = "" And PlanVar3 = "" _
And BusVar1 = "" And BusVar2 = "" And BusVar3 = "" _
Then


strSQL = "Select SaCd, count(MemId)" & _
"From MemberInfoFacets " & _
"Where GroupID IN ('" & GroupVar1 & "','" &
GroupVar2 & "', '" & GroupVar3 & "') " & _
" And ClassID IN ('" & ClassVar1 & "','" &
ClassVar2 & "', '" & ClassVar3 & "') " & _
" AND MemDate = " & INDV & _
" GROUP BY SaCd"

'MemberInfo data for the GroupID and BusCat
ElseIf ClassVar1 = "" And ClassVar2 = "" And ClassVar3
= "" _
And PlanVar1 = "" And PlanVar2 = "" And PlanVar3 = "" _
Then

strSQL = "Select SaCd, count(MemId)" & _
"From MemberInfoFacets " & _
"Where GroupID IN ('" & GroupVar1 & "','" &
GroupVar2 & "', '" & GroupVar3 & "') " & _
" And BusCat IN ('" & BusVar1 & "','" &
BusVar2 & "', '" & BusVar3 & "') " & _
" AND MemDate = " & INDV & _
" GROUP BY SaCd"
'MemberInfo data for the GroupID and ClassID and PlanID
Else

strSQL = "Select SaCd, count(MemId)" & _
"From MemberInfoFacets " & _
"Where GroupID IN ('" & GroupVar1 & "','" &
GroupVar2 & "', '" & GroupVar3 & "') " & _
" And ClassID IN ('" & ClassVar1 & "','" &
ClassVar2 & "', '" & ClassVar3 & "') " & _
" And PlanID IN ('" & PlanVar1 & "','" &
PlanVar2 & "', '" & PlanVar3 & "') " & _
" AND MemDate = " & INDV & _
" GROUP BY SaCd"

End If



All times are GMT +1. The time now is 08:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com