#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    65
    Rep Power
    15

    Iterating thru cells in Excel 2010


    Hello,

    I am not sure why I am getting this error with line If statement in the code below...any ideas are appreciated. Get UNKNOWN RUNTIME ERROR

    Code:
    ' do excel stuff	
    Set xl = CreateObject("Excel.Application")
    	
    ' no need to launch excel
    xl.visible = False
    	
    ' specify excel file path and name
    sExcelPath = CurProjDir & "\comp_pins_nets.xlsx"	
    	
    'Set wb = xl.Workbooks.Open(sExcelPath)	
    	
    Set wb = xl.Workbooks.Open(sExcelPath, ,ReadOnly)
    		
    Set oCurWorkSheet = wb.Worksheets("Sheet1")
    			
    'Find used rows & cols
    usedColsCount = oCurWorkSheet.UsedRange.Columns.Count
    usedRowsCount = oCurWorkSheet.UsedRange.Rows.Count	
    
    'Find column & row that has "Pin Name"		
    For row = 0 To usedRowsCount	
       For column = 0 To usedColsCount		
         If oCurWorkSheet.Cells(row, column).Value = "Pin Name" Then
    	iRow = row
    	iCol = column				
        End If			
       Next			
    Next
  2. #2
  3. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    Rows and Columns start at 1 not 0.
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    65
    Rep Power
    15
    Originally Posted by medialint
    Rows and Columns start at 1 not 0.
    Thank you very much
  6. #4
  7. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    You could just do something like this instead of looping through the whole worksheet:

    Code:
        With xl.ActiveSheet
            nRow = .Cells.Find("pin name").Row
            nCol = .Cells.Find("pin name").Column
        End With
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    65
    Rep Power
    15
    Originally Posted by medialint
    You could just do something like this instead of looping through the whole worksheet:

    Code:
        With xl.ActiveSheet
            nRow = .Cells.Find("pin name").Row
            nCol = .Cells.Find("pin name").Column
        End With
    Thank you again

IMN logo majestic logo threadwatch logo seochat tools logo