Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7403205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:00:00+00:00 2026-05-29T05:00:00+00:00

I have 4 different values, i want to check 4 values with 4 different

  • 0

I have 4 different values, i want to check 4 values with 4 different combination

Code

Dim tot1, tot2, tot3, to4 As Variant
Dim item1, item2, item3, item4 As Variant     

    For Each item1 In tot1
         For Each item2 In tot2
            For Each item3 In tot3
                For Each item4 In tot4
             If item1 = "All" And item2 <> "All" And item3 <> "All" And item4 <> "All" Then '1
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company = '" & item1 & "' and Division <> '" & item2 & "' and Department <> '" & item3 & "' and Location <> '" & item4 & "'"
                ElseIf item1 <> "All" And item2 = "All" And item3 <> "All" And item4 <> "All" Then '2
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company <> '" & item1 & "' and Division = '" & item2 & "' and Department <> '" & item3 & "' and Location <> '" & item4 & "'"
                ElseIf item1 <> "All" And item2 <> "All" And item3 = "All" And item4 <> "All" Then '3
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company <> '" & item1 & "' and Division <> '" & item2 & "' and Department = '" & item3 & "' and Location <> '" & item4 & "'"
                ElseIf item1 <> "All" And item2 <> "All" And item3 <> "All" And item4 = "All" Then '4
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company <> '" & item1 & "' and Division <> '" & item2 & "' and Department <> '" & item3 & "' and Location = '" & item4 & "'"
                ElseIf item1 = "All" And item2 = "All" And item3 <> "All" And item4 <> "All" Then '1 & 2
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company = '" & item1 & "' and Division = '" & item2 & "' and Department <> '" & item3 & "' and Location <> '" & item4 & "'"
                ElseIf item1 = "All" And item2 <> "All" And item3 = "All" And item4 <> "All" Then '1 & 3
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company = '" & item1 & "' and Division <> '" & item2 & "' and Department = '" & item3 & "' and Location <> '" & item4 & "'"
                ElseIf item1 = "All" And item2 <> "All" And item3 <> "All" And item4 = "All" Then '1 & 4
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company = '" & item1 & "' and Division <> '" & item2 & "' and Department <> '" & item3 & "' and Location = '" & item4 & "'"
                ElseIf item1 <> "All" And item2 = "All" And item3 = "All" And item4 <> "All" Then '2 & 3
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company <> '" & item1 & "' and Division = '" & item2 & "' and Department = '" & item3 & "' and Location <> '" & item4 & "'"
                ElseIf item1 <> "All" And item2 = "All" And item3 <> "All" And item4 = "All" Then '2 & 4
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company <> '" & item1 & "' and Division = '" & item2 & "' and Department <> '" & item3 & "' and Location = '" & item4 & "'"
                ElseIf item1 <> "All" And item2 <> "All" And item3 = "All" And item4 = "All" Then '3 & 4
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company <> '" & item1 & "' and Division <> '" & item2 & "' and Department = '" & item3 & "' and Location = '" & item4 & "'"
                ElseIf item1 = "All" And item2 = "All" And item3 = "All" And item4 <> "All" Then '1 & 2 & 3
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company = '" & item1 & "' and Division = '" & item2 & "' and Department = '" & item3 & "' and Location <> '" & item4 & "'"
                ElseIf item1 = "All" And item2 = "All" And item3 <> "All" And item4 = "All" Then '1 & 2 & 4
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company = '" & item1 & "' and Division = '" & item2 & "' and Department <> '" & item3 & "' and Location = '" & item4 & "'"
                ElseIf item1 = "All" And item2 <> "All" And item3 = "All" And item4 = "All" Then '1 & 3 & 4
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company = '" & item1 & "' and Division <> '" & item2 & "' and Department = '" & item3 & "' and Location = '" & item4 & "'"
                ElseIf item1 <> "All" And item2 = "All" And item3 = "All" And item4 = "All" Then '2 & 3 & 4
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company <> '" & item1 & "' and Division = '" & item2 & "' and Department = '" & item3 & "' and Location = '" & item4 & "'"
                ElseIf item1 <> "All" And item2 <> "All" And item3 <> "All" And item4 <> "All" Then '1 & 2 & 3 & 4
                    sSQL = "Insert into table1 Select Distinct Emp_Code from Employee Where Company = '" & item1 & "' and Division = '" & item2 & "' and Department = '" & item3 & "' and Location = '" & item4 & "'"
                End If
        Next
            Next
         Next
    Next

The above mentioned code is working, but code is very hard for checking the 4 values with combination,
Incase if the checking values is 6 then it will be very difficult to write a combination….

Any other alternative method is available…?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:00:00+00:00Added an answer on May 29, 2026 at 5:00 am

    I think you havnt mention the exact structure of your data, otherwise there would have been a better code example, however, try your own code with little modification

        Dim tot1 As New Collection, tot2 As New Collection, tot3 As New Collection, tot4 As New Collection
    Dim item1, item2, item3, item4 As Variant
    Dim str As String
    
    tot1.Add "All"
    tot1.Add "2"
    tot1.Add "3"
    tot1.Add "4"
    
    tot2.Add "1"
    tot2.Add "2"
    tot2.Add "3"
    tot2.Add "All"
    tot2.Add "5"
    
    tot3.Add "1"
    tot3.Add "All"
    tot3.Add "3"
    tot3.Add "4"
    tot3.Add "5"
    tot3.Add "6"
    
    tot4.Add "1"
    tot4.Add "All"
    tot4.Add "3"
    
    
    For Each item1 In tot1
         For Each item2 In tot2
            For Each item3 In tot3
                For Each item4 In tot4
                   str = vbNullString
                   If item1 = "All" Then str = str & "& 1 "
                   If item2 = "All" Then str = str & "& 2 "
                   If item3 = "All" Then str = str & "& 3 "
                   If item4 = "All" Then str = str & "& 4 "
                   Debug.Print item1 & "," & item2 & "," & item3 & "," & item4 & " -> " & Mid$(Trim$(str), 2)
                Next
            Next
         Next
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to submit a form that have many checkboxes with different values, using
Various online services have different values for maximum year of expiry, when it comes
I have one key but different values for that key. I tried HashTable but
I have an object with different values that is name,nameid, lifebeging,lifeEndiging .... etc, for
I have a table with different values for different countries, for example: id| country
I have ArrayProxy filled with different values, and after tossing it in iterator and
i have a function to calculate several different values: int ASPfile::get_dimensions(int* Lat, int* Lon,
I have table nol_voa with different values and I am importing xml file with
Suppose I have 3 radio buttons with different values for each radio button and
Lets say I have 4 different values A,B,C,D with sets of identifiers attached. A={1,2,3,4,5}

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.