AbeeCrombie
AbeeCrombie

Reputation: 607

How to insert records into SQL server from Excel

I am not great at programming but I am getting by and I just want to update a sheet in excel into a table in SQL server 2012.

I can create the connection, insert HARD values but for some reason I cannot figure out how to insert ranges.

That is, the following code works fine:

objConnection.Execute "USE database1 INSERT INTO tblExposure(AssetID, Name) VALUES  (1234, 'Metoo')" 

But, when I try to substitute a range, like Range.("A3").Value, I cant get it working.

objConnection.Execute "USE database1 INSERT INTO tblExposure(AssetID, Name) VALUES  (Range("A3").Value, 'Metoo')" 

Thanks for the help

Upvotes: 2

Views: 2445

Answers (1)

Fionnuala
Fionnuala

Reputation: 91376

You need to put the range outside the quotes:

"USE database1 INSERT INTO tblExposure(AssetID, Name) VALUES  (" _
   & Range("A3").Value & ", 'Metoo')"

Upvotes: 3

Related Questions