Greetings All,
I'm working on a VBA macro to rapidly import a series of data sets from delimited text file. The idea is that I import the data into the 'Import' worksheet, wherein a number of variables (n, h, f and d) are calculated using worksheet functions. I then use these calculated variables in conjunction with a loop to copy and paste each data set into another worksheet.
Sub ASCII_Import_Filter()
'
' ASCII_Import_Filter Macro
'
Dim m As Integer ' loop cache
Dim n As Integer ' number of data sets
Dim h As Integer ' size of header
Dim f As Integer ' size of footer
Dim d As Integer ' size of data set
Dim l As Integer
'
n = Sheets("Import").Range("data_sets").Value
h = Sheets("Import").Range("header").Value
d = Sheets("Import").Range("data_points").Value
f = Sheets("Import").Range("footer").Value
l = m - 1
'
' Import y-series data
Sheets("Import").Select
Range(Cells(h, 4), Cells((h + d), 4)).Select
Selection.Copy
Sheets("FLEX Data").Select
Range(Cells(10, 1), Cells(10, 1)).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'
For m = 1 To n
' Import x-series data
Sheets("Import").Select
Range(Cells(((m * h) + (l * d) + (l * f)), 5), Cells(((m * h) + (m * d) + (m * f)), 5)).Select
Selection.Copy
Sheets("FLEX Data").Select
Range(Cells(10, (m + 2)), Cells(10, (m + 2))).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next m
'
End Sub
As you can probably see the loop cycles through n number of times (i.e. once for each data set). For some reason however I keep getting a run-time error(s) at the highlighted line, an oddity since this line is almost identical for the earlier line of code outside of the loop. This is the specific error I recieve:
Run-time Error '1004':
Application-defined or object-defined error
Can anyone see any glaring errors in there that I've missed? I am rather new to VBA afterall. I'm told that using select is unwise in these circumstances, so I would also appreciate it if someone better verse with VBA could demonstrate how to copy a range from one worksheet to a range in another. Put obviously the more pressing matter at present is getter the loop working, I had it working at some point yesterday, but for the life of me I cannot think how I got it working and/or what I did to break it! 
Any assistance would be greatly appreciated.
Kind Regards,
Anubeon.
Bookmarks