I'm an all-round programmer, but VB.NET and I never get along.
I have one excel file with a bunch of data. I want to read each row, check if column X is a specific value and if so, write that row to a new excel file (without adding empty rows in output file).
The 'check if column = X' is just to get things started.
I'll post my code below, but it's the result of trying 20 different approaches and none of them seem to work. Right now my variable 'value_range' in ReadData has a 'Cells' property with all the cells of the first excel file, but I can't figure out how to get one row out.
I'm also outputting "Height", but I'm guessing that that's the actual height of a row in excel, which is useless to me. I'm really frustrated because of the terrible documentation (I'm using these pages: http://msdn.microsof..._members.aspx). If there's a better documentation out there, please let me know.
So this is my code so far. It won't make that much sense, but I don't want you guys to think I'm not trying.
Private Sub ReadData() ' GetCell = mExcelApp.Sheets(SheetName).cells(Column, Row).value Try Dim sheet As Excel.Worksheet = mExcelApp.Sheets(strSheetName) Dim rowCount As Integer = sheet.UsedRange.Rows.Count Dim columnCount As Integer = sheet.UsedRange.Columns.Count Dim rows As Excel.Range = sheet.UsedRange.Rows For c As Integer = 1 To 100 Dim value_range As Excel.Range = rows.Range(c) trace("Height: " & value_range.Height & ", Count: " & value_range.Count) 'AddRow(value_range.Columns) Next Catch ex As Exception trace(ex.Message) End Try End Sub
'Never got it to write data to my output file, but I'm focusing on the filtering first Public Sub AddRow(ByVal row As Range) trace("Printing row " & outputcounter) Dim value_range As Excel.Range = outputsheet.Range("A" & outputcounter).Resize(1, row.Height).Columns trace("Height: " & value_range.Height & ", Count: " & value_range.Count) trace(vbCrLf) outputcounter = outputcounter + 1 value_range.Value2 = row End Sub