Pasting/Compiling Data To The End Of A File

G

Guest

Hello, I have written a macro to import data into an excel file, but
currently have the data always being copied into a designated cell - "A1".
What I actually need to do is have all the information continually compile.

For instance, there may be 10 items during the first import, which would
value rows 1 through 10. A subsequent import may then have 15 items and then
the data should go to the next available row, row 11.

Can someone suggest code to accomplish this?

Any and All Help Will Be Appreciated
 
G

Guest

This is example assumes that the data starts in A1 and there aren't any
blank lines in the data.

Sub NextRow()

Dim wb As Workbook
Dim ws As Worksheet
Dim l As Long
Set wb = ActiveWorkbook
Set ws = wb.Worksheets("Sheet1")
Dim r As Range

'Activate Sheet1 in the current workbook and select cell A1
ws.Activate
Range("A1").Select

'Select the current contiguous region and name it
Selection.CurrentRegion.Select
Selection.Name = "CurrentData"

'count the number of rows in the named range
l = Range("CurrentData").Rows.Count
'Select the next available cell in column by
'adding 1 to the total count of row in the
'named range
Cells(l + 1, 1).Select

Set r = Nothing
Set ws = Nothing
Set wb = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top