0

So I am very new to VBA (never written anything in it before) I have been searching for a solution, but I haven't managed to find anything that does what I want.

I need to import data from a CSV and insert it into the next empty column beyond a certain column.

My first few columns will be occupied by buttons linking to "stuff" so these can't be used for data.

So I need a script to do this:

1) Import data from a single column csv file. 2) paste data into the next empty column which is after Column E.

I fully appreciate that SO isn't a code writing platform and I feel pretty dodgy asking this but I have been trying for hours and seem to have exhausted any resources that I've come across.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Joe Smart
  • 751
  • 3
  • 10
  • 28
  • 1
    Have you tried http://stackoverflow.com/questions/19028725/copy-and-paste-last-used-column-into-next-available-column/19029058#19029058 or http://stackoverflow.com/questions/11883256/copy-last-column-with-data-on-specified-row-to-the-next-blank-column or http://stackoverflow.com/questions/11926972/excel-vba-finding-the-last-column-with-data ? – SierraOscar Sep 11 '15 at 12:45

1 Answers1

1

The following codes should help you:

Option Explicit
Sub work()
Dim i As Integer
Dim main As Worksheet
Dim reference As Worksheet

Set main = ActiveSheet
Workbooks.Open "C:\Users\vqm1628\Downloads\b.csv"
Set reference = ActiveSheet
Range(Cells(1, 1), Cells(Cells(1, 1).End(xlDown).Row, 1)).Copy _
    Destination:=main.Cells(1, main.Cells(1, 100).End(xlToLeft).Column + 1)
'the line above only applies if the first five columns have values
Application.DisplayAlerts = False
Workbooks("b.csv").Close
Application.DisplayAlerts = True
End Sub

I hope it may help you;)

theVerse
  • 904
  • 1
  • 7
  • 14