Jack_Jones
asked on
Visual Basic Listview / Excel
I am trying to use this code once a .xlsx file is open to load all items starting from A2 - A1000 to load into the listview1 nambed compliantskus. Thanks for the help, and look forward to get this to work.
Dim i As Integer
Do Until i = 1000
For incnumber As Integer = 1 To 1000
Label4.Text = i
compliantskus.Items.Add(oSheet.Range("A" & incnumber).Value)
i = i + 1
Next
Loop
So you want to have a listview object (located in the Excel worksheet) load using the data found in cells A2-A1000, correct? Where does VB.Net come into play? Does your question only deal with Excel? Please correct me if I am wrong.
ASKER
I have a listview in visual basic that I want to generate data into from an excel sheet starting with A2 - A1000.
You are using VB.Net in Visual Studio?
ASKER
it's Visual Studio 2010 code in VB.
objExcel.Range("A2").Select 'Select Cell to start from
Do Until objExcel.ActiveCell.Value = "A1000" 'Add items until row 1000
RowActive = objExcel.ActiveCell.Row 'Get current row
Set itmX = ListView1.ListItems.Add
itmX = objExcel.Cells(RowActive, 1).Value 'Adds Value from Current Row and Column 1
itmX.SubItems(1) = objExcel.Cells(RowActive, 2).Value 'Adds value from Current Row and Column 2
objExcel.ActiveCell.Offset(1, 0).Select
Loop
This is how to do it in VB, but im confused with your statement Visual Studio 2010 in VB
VB is Visual Basic
VS 2010 is VB.net if im not mistaken?
Hope this helps.
Storm
ASKER
No luck with that Storm, it gives me lots of red errors under objExcel, RowActive, itmX. Here is what I fully am working with.
Dim oExcel, oWorkbook, oSheet, oNewSheet
oExcel = CreateObject("Excel.Application")
oWorkbook = oExcel.Workbooks.Open("C:\Inventory\database.xlsx")
oSheet = oWorkbook.Sheets("PCDB")
Dim i As Integer
Do Until i = 1000
For incnumber As Integer = 1 To 1000
compliantskus.Items.Add(oSheet.Range("A" & incnumber).Value)
i = i + 1
Next
Loop
oWorkbook.Save()
oExcel.Quit()
oNewSheet = Nothing
oSheet = Nothing
oWorkbook = Nothing
oExcel = Nothing
ASKER
Yes I use VS 2010
Got to go...will help more later if you need me.
ASKER
sl8rz thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sure do ;)
ASKER
Howdy CodeCruiser, good to see ya here!
Dim oExcel, oWorkbook, oSheet, oNewSheet
oExcel = CreateObject("Excel.Application")
oWorkbook = oExcel.Workbooks.Open("C:\Inventory\database.xlsx")
oSheet = oWorkbook.Sheets("PCDB")
Dim i As Integer
Do Until i = 1000
For incnumber As Integer = 1 To 1000
compliantskus.Items.Add(oSheet.Range("A" & incnumber).Value)
i = i + 1
Next
Loop
oWorkbook.Save()
oExcel.Quit()
oNewSheet = Nothing
oSheet = Nothing
oWorkbook = Nothing
oExcel = Nothing
ASKER
Here this might help;
System.Reflection.Ambiguou sMatchExce ption was unhandled
System.Reflection.Ambiguou
Did you try replacing your loop code with mine? You are running two loops in your code which is not needed. Also, which line generates the error?
ASKER
Yep still same error
Which line?
ASKER
compliantskus.Items.Add(oS heet.Range ("A" & incnumber).Value
ASKER
The first executed add item in the loop.
For i As Integer = 0 To 35
ListView1.Items.Add(oSheet.Range("A" & i + 3).Value) <--- Flags Error
ListView1.Items(i).SubItems.Add(oSheet.Range("B" & i + 3).Value)
ListView1.Items(i).SubItems.Add(oSheet.Range("C" & i + 3).Value)
Next
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Fixed Loop to rows, and changed it to + 1, error went bye bye.