Macro to import CSV works but I need to dynamically change the destination cell

yorkshirelad

Board Regular
Joined
Aug 18, 2003
Messages
100
I have a macro that imports a csv file into an existing worksheet.

It work fine but instead of the destination cell being fixed as now to A2, I need the destination cell to be the first blank cell in column A.

This means if I already have fifteen rows of data the new imported data will start at A16, if I have 20 rows of data the new imported data will start at A21

This is the working macro - any help would be really appreciated.

Sub importing_csv_cliente()
Dim file As String
Dim src As Worksheet
Dim dst As Worksheet
Application.ScreenUpdating = False


'-- determine destination range
Set dst = ActiveSheet

'-- determine source csv file
file = "cliente.csv"

'-- determine data source range
Set src = Workbooks.Open(file).Worksheets(1)

'-- copy the data
src.Range("A1:l5").Copy dst.Range("A2")

'-- close csv file
src.Parent.Close False

End Sub

Many thanks
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try

Code:
src.Range("A1:l5").Copy dst.Range("A" & Rows.Count).End(xlUp).Offset(1)
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,448
Members
452,915
Latest member
hannnahheileen

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