EXCEL Issue retriving data from SQL


New Member
Jan 30, 2009
Hello ppl,

The first thing of all i apologize myself for my bad English.

Ok, a little bit of history, i write a VBA macro for EXCEL that retrieves information from an SP in SQL Server 2K, and is not the first macro that i write, i have already writed a lot of this macros but this is the first time i get this issue, and i can't figure it out how to solve it.

I have a query that retrieve information from some tables, it group the results, and make some math’s and return a single row per document, i tested this view and works fine when you execute it from Query Analyzer, or the MMC

The following image is an example of the data returned by the query in the query analyzer.

As you can see there is a set of records returned, but we will focus on the one higlighted, only one row returned by the SP, also you can notice that I’m using the tools from SQL Server 2008, but the server is 2K (this is just a note)

Now i execute the same stored procedure from my macro in EXCEL, and sometimes not always i get some changed rows, and not all, only one or two records.
The following image shows the same record i already show in the last image but in EXCEL the row is ungrouped, why? How? i don’t know. also you can notice that if you sum the values of the cols SUBTOTAL, IVA, IMPORTE, you get the same values that i get in the Query Analyzer. (also the image showed uses office 2007 pofessional, but i get the same result in Office 2K, and 2003)

So what things I have already tried,
- I change the way I import the data from SQL to EXCEL, I used the instruction varHoja.Range().CopyFromRecordset rstResultados, also i write a routine that gets value by value the result from the recordset and copy it in the EXCEL Sheet. I change the way i connect to the database, ODBC, ADO, ADO.NET

- I rewrite the query thinking that it was the cause but i already change it two times, and i get the same result.
So at this point i feel a little bit frustrated, and i hope someone in this forum can help me to figure it out this issue.

Thanks in advance and best regards.

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...