+ Reply to Thread
Results 1 to 8 of 8

need to grab info from SQL table, place into macro, and run a loop until end of table

  1. #1
    Registered User
    Join Date
    02-20-2014
    Location
    Portland, Oregon
    MS-Off Ver
    Excel 2007
    Posts
    16

    need to grab info from SQL table, place into macro, and run a loop until end of table

    I've got all the parts but lack the programming knowledge to apply what I want. I've built a SQL query that will generate a directory listing of all the files existing in the directory that will store the files that need to be processed along with the column that contains the information I need to edit for each file. (I have output the results to the file startpos.xls)

    The macro will open the file specified, sort it by the specified column, and delete all blanks,and values between -25 to 0, and the values of 'del' or 'memo' then save the resulting file to a different directory then loop to begin again with the next item on the list until completed.

    the macro portion looks like this

    Please Login or Register  to view this content.
    The items in bold are the items that would need to be set as variables and prefilled with the data from the SQL table and obviously a loop and the SQL connection information. Can anyone help me with the steps I'm missing to make this work?
    Attached Files Attached Files
    Last edited by alansidman; 03-04-2014 at 12:36 PM. Reason: code tags

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: need to grab info from SQL table, place into macro, and run a loop until end of table

    It is fairly simple.

    If you can post your code or edit your post and add the code tags, that would be easier for us to modify your code. In the advanced editor for a replace, click the # to add code tags and paste code between them.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2403 Win 11 Home 64 Bit
    Posts
    23,810

    Re: need to grab info from SQL table, place into macro, and run a loop until end of table

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between
    Please Login or Register  to view this content.
    tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    02-20-2014
    Location
    Portland, Oregon
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: need to grab info from SQL table, place into macro, and run a loop until end of table

    thank you, and sorry for my error

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: need to grab info from SQL table, place into macro, and run a loop until end of table

    You will need more error checking I suspect. You might also want to make your sort range more dynamic.

    In a module in that file:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-20-2014
    Location
    Portland, Oregon
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: need to grab info from SQL table, place into macro, and run a loop until end of table

    I think I was in error by leaving out the SQL portion of the code because I do not see how to reference the SQL results.

    Please Login or Register  to view this content.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: need to grab info from SQL table, place into macro, and run a loop until end of table

    You should have the results of the query in the recordset tblSellpos.

    There are various ways to refer to them, really depends what you are you doing.

    For example, you could loop through the recordset like this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  8. #8
    Registered User
    Join Date
    02-20-2014
    Location
    Portland, Oregon
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: need to grab info from SQL table, place into macro, and run a loop until end of table

    Thank you, by combining both your suggestions I have code that works to meet my needs. The end result code is as follows for anyone who chooses to follow up on this thread.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help: Macro or multi-step formula needed in place of a pivot-table method.
    By katiedegu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-21-2013, 10:29 AM
  2. [SOLVED] Place macro button to the right of pivot table
    By bcn1988 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2013, 09:56 AM
  3. VBA Grab Pivot Table Grouping Value
    By gingank in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-14-2012, 03:43 AM
  4. How to link one info from one table to another data in another table?
    By xia0lis in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-27-2012, 07:04 AM
  5. [SOLVED] How do i grab a table value to fill a cell?
    By gail1166 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-04-2006, 12:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1