+ Reply to Thread
Results 1 to 2 of 2

Thread: using excel range as sql variable in vba macro in excel

  1. #1
    Registered User
    Join Date
    01-02-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2007
    Posts
    1

    Smile using excel range as sql variable in vba macro in excel

    Hello

    I'm a newbe, so please bear with me.

    I'm having problems doing the following in VBA for Excel

    A first piece of VBA script in an active Excel worksheet accesses an external DB and fills columns E from row 10 onwards with social security numbers. So far so good

    A second piece of VBA script is supposed to get the first entry in the social security column (>E10) and use that value in a VBA macro that contains a sql command. The aim is for SQL to get to a second external DB and extract name and address for the person belonging to the social security number.
    Name and number are to be put in column C and D of the same row the social security number was taken from.

    Then the VBA script is to proceed to the next row in column E and do it all over again for the second social security number. And so on until there are no more numbers in column E.

    If I put the social security number in the SQL string as an exact numerical value (like 1234567) it works. I don't now how to refer to sucessive rows in column E however.

    Some stuff I'm using

    Dim client As String
    Dim Name As String

    Const column_Client As String = "C"
    Const Column_Name As String = "D"

    ' Column E is define as follows
    Dim RgSocialSec As Range

    Set RgSocialSec = Range("E10:E3000").Select


    Really stuck with this
    Many thanks for any help

  2. #2
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,230

    Re: using excel range as sql variable in vba macro in excel

    Welcome to the forum. Please note ...

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    That said, try changing:

    Set RgSocialSec = Range("E10:E3000").Select

    to just:

    Set RgSocialSec = Range("E10:E3000")

    Regards, TMS

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0