Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2012
    Posts
    2

    Red face Unanswered: using excel range as sql parameter in vba macro

    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
    Join Date
    Jan 2012
    Posts
    2

    refering to excel rang as sql parameter in VBA

    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

Tags for this Thread

Posting Permissions

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