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 8815707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:26:42+00:00 2026-06-14T04:26:42+00:00

I created a loop in VBA that should change a variable (j) in the

  • 0

I created a loop in VBA that should change a variable (j) in the strSql portion of the code. My output columns on the excel sheet are all indentical. That means that the changing variable j is not taken into consideration in the strsql string. Does anybody know how to use a proper changing variable in this case? Thanks in advance

Set rs = New ADODB.Recordset

     For j = 1 To 6


    strSql = "SELECT COUNT(*) FROM( " & _
     "SELECT COUNT(*) as nbp FROM `order`   " & _
     "JOIN user ON user.id = order.destination_id   " & _
     "AND DATEDIFF(date_added , register_date) <= j" & _
     "GROUP BY destination_id)  c  " & _
     "GROUP BY nbp " & _
     "ORDER BY c.nbp ASC ; "



    rs.Open strSql, oConn, adOpenDynamic, adLockPessimistic

    res = rs.GetRows

    rs.Close

    For i = 1 To 2
    Cells(i, j) = res(0, i - 1)
    Next i
    Next j
  • 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-06-14T04:26:43+00:00Added an answer on June 14, 2026 at 4:26 am

    You need to move j out of your string

    register_date) <= j” &

    To

    register_date) <= ” & j &

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created some python code which creates an object in a loop, and
because obj, the playingCard object is created inside a nested for loop does that
I have created a loop that templates my data and then appends it into
I've created a loop where a variable is used to test if the current
I created a while loop that produces random images for the user. Every time
Trying to use Excel VBA to capture all the file attributes from files on
I have an excel sheet that has dde links to real time market data.
I have an Excel 2003 VBA program that creates an SQL string that way:
I have an excel sheet that I am wanting to extract data from and
I'm using the VBA code here to copy all the charts and tables from

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.