0

I want to copy the entire column from excel to array list to compare the data.

 Dim file_name As New ArrayList
        file_name.Add(xlworksheet1.Range("a1").EntireColumn)
        Console.WriteLine(file_name)
        For Each Name1 In file_name
            Console.WriteLine(Name1)
        Next
halfer
  • 19,824
  • 17
  • 99
  • 186
harshitha
  • 21
  • 1

1 Answers1

1

This is my suggestion:

Dim file_name As New ArrayList
' find the last row with values
Dim Lr As Integer = xlworksheet1.Cells(xlworksheet1.Rows.Count, 1).End(Excel.XlDirection.xlUp).Row

' loop trough all cells in column 1 (A)
For i = 1 To Lr
    file_name.Add(xlworksheet1.Cells(i, 1).value)
Next

Console.WriteLine(file_name)
For Each Name1 In file_name
    Console.WriteLine(Name1)
Next

also consider using List(of T) instead of ArrayList.

Jonathan Applebaum
  • 5,738
  • 4
  • 33
  • 52