Export only filled cells to access

johanssson

New Member
Joined
Sep 27, 2013
Messages
25
I find an easy way to send data from excel sheet to access database with following VBA code :

Sub SaveOnAccess()


Dim NewCon As ADODB.Connection
Set NewCon = New ADODB.Connection


Dim Recordset As ADODB.Recordset
Set Recordset = New ADODB.Recordset


NewCon.Open "Provider=Microsoft.ace.oledb.12.0;Data Source =C:\Fredrik\ToDoFolders\Pågående\ExcelProjekt\Tidsrapporter\Version 2\Tidsrapport.accdb"
Recordset.Open "Tabell1", NewCon, adOpenDynamic, adLockOptimistic
Recordset.AddNew
Recordset.Fields(0).Value = Range("A2").Value
Recordset.Fields(1).Value = Range("B2").Value
Recordset.Fields(2).Value = Range("C2").Value
Recordset.Fields(3).Value = Range("D2").Value


'''Recordset.Fields(0).Value = Range("A3").Value
'''Recordset.Fields(1).Value = Range("B3").Value
'''Recordset.Fields(2).Value = Range("C3").Value
'''Recordset.Fields(3).Value = Range("D3").Value


'''Recordset.Fields(0).Value = Range("A4").Value
'''Recordset.Fields(1).Value = Range("B4").Value
'''Recordset.Fields(2).Value = Range("C4").Value
'''Recordset.Fields(3).Value = Range("D4").Value


Recordset.Update
Recordset.Close


End Sub



Remaining issue is now how to export all line that has a value in Column A.
A1 is the header so for instance the range A2 - A10 is the range to look into.

So if A3 is filled in with a "name" we export entire row 3 to access. If row A3 is empty we exclude it from the export.

I'm thinking of a While loop and at the same time a rowcount but I can't figure out how to to it together.

My test data is like following :

Name Value1 Value2 Value3 Value4
name1 1...........2........3........4
name2 2...........3........3........2

Thanks in advance!
 
Last edited:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,223,098
Messages
6,170,100
Members
452,301
Latest member
QualityAssurance

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