|
-
Mar 7th, 2017, 08:11 AM
#1
Thread Starter
Lively Member
Finding a row in Excel
Hey,
I need to make a section of code that will search for a term like "1000" and find the row that contains it. (there will never be two the same) and then save that row.
I have this for finding the last row edited:
Code:
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Dim LastRow As Long
Dim lastjn As Integer
Dim newjb As Integer
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Open(My.Computer.FileSystem.SpecialDirectories.MyDocuments + "\job.xlsx")
oSheet = oBook.worksheets(1)
LastRow = oSheet.UsedRange.Rows.Count
So im guessing it will be simular, just searching for a term instead of last edited.
Thanks
VS 2017 - Need as much help as you can give (write it all for me!)
-
Mar 7th, 2017, 09:48 AM
#2
Re: Finding a row in Excel
Take a look at this option:
Code:
Dim cell As String
For x As Integer = 1 To range.Rows.Count
For y As Integer = 1 To range.Columns.Count
cell = DirectCast(range.Cells(x, y), Excel.Range).Value.ToString()
If cell = "1000" Then
'This cell equals 1000, do something with it
End If
Next
Next
-
Mar 7th, 2017, 01:38 PM
#3
Thread Starter
Lively Member
Re: Finding a row in Excel
 Originally Posted by dday9
Take a look at this option:
Code:
Dim cell As String
For x As Integer = 1 To range.Rows.Count
For y As Integer = 1 To range.Columns.Count
cell = DirectCast(range.Cells(x, y), Excel.Range).Value.ToString()
If cell = "1000" Then
'This cell equals 1000, do something with it
End If
Next
Next
Do I need to Dim range as something?
VS 2017 - Need as much help as you can give (write it all for me!)
-
Mar 7th, 2017, 01:49 PM
#4
Re: Finding a row in Excel
Yeah, range would be the cells that you wanted to iterate through.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|