Question : Populate Excel Cells from SQL

I have a spreadsheet were columns A and B contain values that I use in a SQL statement to return data for Coulmns C, D, E and F. I have a function that works just fine returning the data for a single cell but what I want to do is make a single SQL call to get the 4 required values and then write them to columns C,D,E and F all at once. I looked at the ActiveSheet Cells function but can't seem to get it to work.

So to recap: A1 and B1 contain variables that I use as parameters in a SQL call that returns the values for C1, D1, E1 and F1. I then populate A2 and B2 and so on....

Anyone have any suggestions?

Answer : Populate Excel Cells from SQL

Functions returning values to target cells in MS-Excel are scalar by nature - i.e. they can return only one value..

One option would be for the function to concatenate multiple results in a single string separated by delimiters and use string manipulation functions in excel to extract relevant values across cells (by predefined formula entries in the target cells)

Other option would be to convert your scalar function to take in a target range and populate the values within that function/subroutine itself..
Random Solutions  
 
programming4us programming4us