Selecting a value using excel that is offset from a found string and appending it to an excel file

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi guys,
I have a problem using excel ranges in vb.net. I am searching for a value and once this value is found i want to select the cell beneath the found row and paste this into the first empty cell in a new workbook. This workbook will need to be created once by the code and then edited for each subsequent iteration.
My code looks like this to select the range and paste it into an excel file: rng = xlWorkSheet.Range(Result, Result.Offset(-1, 0))
rng.Select()
rng.Copy()
exceptionsList(rng, xlWorkSheet, thefolder, us)
this rng variable is declared as excel.range and works as a result from a search for value routine that I have working in other parts of the code
below here is what I have in the routine exceptionslist rng is a excel range, xlworksheet is a worksheet, thefolder is a save location and us is a value to paste into column A on the first free row.
Clipboard.Clear()
copies the contents of the web borwser onto the clipboard
Clipboard.SetDataObject(cpeCount, False)
Start Excel and get Application object.
oXL = CreateObject("Excel.Application")
If oXL IsNot Nothing Then
oXL = New Excel.Application
oXL.Visible = False
oXL.DisplayAlerts = False
oWB = oXL.Workbooks.Add
oSheet = oWB.Worksheets.Add()
paste the data from the clipboard to excel sheet
Dim rC As Excel.Range = oSheet.UsedRange.Rows
For rows As Integer = 0 To rC.Count
If oSheet.Range("A" & rows).Text IsNot Nothing Then
oSheet.PasteSpecial()
End If
Next
If File.Exists(LCase(folderpath & "exceptions.xls")) = False Then
oWB.SaveAs(LCase(folderpath & "exceptions"))
Else
oWB.Save()
End If

If youre not living on the edge, youre taking up too much room

View the full article
 
Back
Top