Macro -Update sql from Excel ranged cells

Hello,
I use below Code to update SQL table.
Can you please help with setting the range of cells.

This line
FROM Activeorders where Orderno in (6726337,6746668,6746669,6746670)

Need it to be
FROM Activeorders where Orderno in ------- Sheetx.(A2: LAST Row)

cnn.Open xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
cnn.Execute DECLARE yyyyyyyyyyyyyyyyyyyyyyyyyy
BEGIN TRANSACTION
DECLARE Cursor1 CURSOR FOR SELECT orderno
FROM Activeorders where Orderno in (6726337,6746668,6746669,6746670)
OPEN Cursor1   FETCH NEXT FROM Cursor1 Into @ID    WHILE (@@FETCH_STATUS =0)
BEGIN
exec spOrdersW @Orderno = @ID ,@DriverNumber = 3063
FETCH NEXT FROM cursor1        INTO @id    END

Your help is appreciated.
Thanks
W.E.BAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
Use this...

Dim str As String, lrow As Long
    Dim cell As Range, rng As Range
    lrow = Cells(Cells.Row.Count, "A").End(xlUp).Row
    Set rng = Range("A2:A" & lrow)

    For Each cell In rng
        If cell.Value <> "" Then
            If str = "" Then
                str = cell.Value
            Else
                str = cell.Value & "," & str
            End If
        End If


    Next cell

    cnn.Open xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    cnn.Execute DECLARE yyyyyyyyyyyyyyyyyyyyyyyyyy
    BEGIN TRANSACTION
    DECLARE Cursor1 CURSOR FOR SELECT orderno
    FROM Activeorders where Orderno in (str)
    OPEN Cursor1   FETCH NEXT FROM Cursor1 Into @ID    WHILE (@@FETCH_STATUS =0)
    BEGIN
    exec spOrdersW @Orderno = @ID ,@DriverNumber = 3063
    FETCH NEXT FROM cursor1        INTO @id    END

Open in new window


Saurabh...
1
W.E.BAuthor Commented:
Hi Saurabh ,
Thank you for your help,

I got error message
Invalid Column name 'Str'.

FROM Activeorders where Orderno in (str)

Thanks,
0
Saurabh Singh TeotiaCommented:
I'm assuming you are using double quotes as well as it's not pick str value it will be this..

" FROM Activeorders where Orderno in ("  & str & ")"

Open in new window


Also check in immediate window whats the value of str you see ??
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

W.E.BAuthor Commented:
I'm not getting any errors,
but , nothing is being updated.

Not sure if this is correct, I tried adding quotes
" FROM Activeorders where Orderno in (' "  & str & " ')"

I get error
Conversion failed when converting the varchar value xxxxx to data type int.

Thanks again,
0
W.E.BAuthor Commented:
ALL good,
I was on the wrong database,

very much appreciated your time and help.
0
Saurabh Singh TeotiaCommented:
Wass..You are welcome..always happy to help.. :-)

Saurabh...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.