Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Visual Basic/VB.net, in the Visual Studio IDE, I am generating an excel file

ID: 3912373 • Letter: I

Question

In Visual Basic/VB.net, in the Visual Studio IDE, I am generating an excel file from my program. I'd rather not copy and paste the code here because it is too long. My problem is, I need to copy a column of data from another excel file, to the excel file my program automatically creates. How can I write the program so that I get a column from an excel file and copy it to another excel file? Please provide the answer in the form of code. I am note sure if it matters, but the excel files I am using are .csv files.

Explanation / Answer


Sub test1()

'Assign input and output sheets to ws1 and ws2 respectively

'input.csv is the input file location

Set ws1 = Workbooks("input.csv").Sheets("Sheet1")

'output.csv is the output file location
Set ws2 = Workbooks("output.csv").Sheets("Sheet1")

'copying the data from input file. Range("A:A") means selecting entire column A.
'If you want specific range like A and B till 100 rows then it will be like Range("A1:B100")
ws1.Range("A:A").Copy

'Select the particular cell where we want to start pasting the data. In this case cell 1,1 which imply first cell of first column
ws2.Cells(1, 1).Select

'paste the data
ws2.Paste

End Sub

If you still have any doubts please comment.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote