0 votes
in VBA by Beginner (2 points)
i want to use the input value in sqlstr in my VBA using the reange from the excel sheet
by Skilled (605 points)

Can you give more details, please?

Do you mean ??

sqlstr = Range("A1").Value

Or Range("A1").Value=sqlstr

 

by Beginner (2 points)
I want to add multiple values in the range and range is given from excel where marco will be used
by Beginner (2 points)
strSql = "select mp.asin,mp.item_name from booker.d_mp_asins mp where mp.is_deleted = 'N' and mp.marketplace_id = '44571' and mp.asin =" & Worksheets("ASIN").Range("A2").Value
by Beginner (2 points)
for above code i want to use next value from next cell

should i use loop if yes how?
by Skilled (605 points)
Fine .. You did it in the line you posted

Why would you like to use loops?
by Skilled (605 points)
The next value will be in another variable ..so you would use loop
by Beginner (2 points)

Hi Yasser,

 

Thank you for the help,

Can u tell me where my code went wrong.

 

Sub ImportASIN()

    Dim asin As New ADODB.Connection
    Dim asinc As New ADODB.Command
    Dim asinrs As New ADODB.Recordset
    Dim strSql As String
    Dim asins As String
    Dim asinct As String
    Dim target As Range
    Dim ws As Worksheets
    Dim i As Integer
    
    
    
    
    With asin
        .ConnectionString = "xxxxxxx---xxxxxxxx"
        .Open
        
    End With
    
        
     
        
    Set asin = New ADODB.Connection
    Set asinrs = New ADODB.Recordset
    
    For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        strSql = "select mp.asin,mp.item_name from booker.d_mp_asins mp where mp.is_deleted = 'N' and mp.marketplace_id = '44571' and mp.asin =" & Worksheets("ASIN").Range("A" & i).Value
        Debug.Print strSql
        
    Next i
    
        
    ws.Cells(target.raw + 1, target.Column).CopyFromRecordset asinrs
  
    
    
   
    
        
      
    asin.Close
    asinrs.Close
       
    
    
    Set asinrs = Nothing
    Set asin = Nothing
    
  
End Sub

 

by Skilled (605 points)

May be you have another sheet selected or active (not ASIN sheet)

    With Worksheets("ASIN")
        For i = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
            strSql = "select mp.asin,mp.item_name from booker.d_mp_asins mp where mp.is_deleted = 'N' and mp.marketplace_id = '44571' and mp.asin =" & .Range("A" & i).Value
            Debug.Print strSql
        Next i
    End With

 

1 Answer

0 votes
by Skilled (605 points)
edited by

You mean there will be a value and you would like to add another value to the existing one as the idea of concatenation or what ..

Put the inputs and your expected output ..

Sub Test()
    Dim i%, strSql$
    
    For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        strSql = "select mp.asin,mp.item_name from booker.d_mp_asins mp where mp.is_deleted = 'N' and mp.marketplace_id = '44571' and mp.asin =" & Worksheets("ASIN").Range("A" & i).Value
        Debug.Print strSql
    Next i
End Sub

 

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.

Register

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...