Export Worksheet to SQL 2008 R2

RobSully

New Member
Joined
Jul 16, 2012
Messages
14
I wave a ms Excel Workbook that imports some comma delimited files does some maintenance and combines everything into a single worksheet. Everything works fine and the sheet and the process is very stable. After the sheet is worked throughout the day I import the sheet into a SQL 2008 R2 database where it is then used by other groups. My question is is there a way I can code a Macro that will allow an end user to upload that spreadsheet to SQL SERVER without me having to do it?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I wave a ms Excel Workbook that imports some comma delimited files does some maintenance and combines everything into a single worksheet. Everything works fine and the sheet and the process is very stable. After the sheet is worked throughout the day I import the sheet into a SQL 2008 R2 database where it is then used by other groups. My question is is there a way I can code a Macro that will allow an end user to upload that spreadsheet to SQL SERVER without me having to do it?

Yes, I do something similar.

You need to put your database credentials etc into a module and then connect to it - after that, something as simple as
Code:
sqlstr = "Use OTR INSERT INTO dbo.invoices (CRNo,[Hours Billed],[Amount Billed],Date,Client,[Inv No],Grade,[Original CR No],Position,CRID) "
sqlstra = sqlstr & "VALUES ('" & (Range("A" & z).Value & "','" & (Range("B" & z).Value & "','" & (Range("C" & z).Value & "','" & (Range("D" & z).Value & "','" & (Range("E" & z).Value & "','")))))
sqlstrb = sqlstra & (Range("F" & z).Value & "','" & (Range("G" & z).Value & "','" & (Range("H" & z).Value & "','" & (Range("I" & z).Value & "','" & (Range("J" & z).Value & "')")))))
gosql.Execute (sqlstrb)
Range("A" & z & ":" & "GG" & z).Select
 
Upvote 0

Forum statistics

Threads
1,215,689
Messages
6,126,217
Members
449,303
Latest member
grantrob

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top