CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    Location
    PA, USA
    Posts
    3

    selecting a certain cell in excel

    Hi all,
    I am working on a project that is using the VB in Excel. I am trying to figure out how to select a certain cell. Basically, I have a column of numbers and these numbers start at 21 then go down to about 3 and then climb back to 21. They are in one column and consist of 4,120 rows. I have an inputted value, say 13, I need to search though the column of numbers and select the first cell that is just before the cell that is <= 13. Then I need to use that row number to identify where the data should start being used for calculation i.e. delete all data above that row indicator. An suggestions would be greatly appreciatted.


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: selecting a certain cell in excel

    Set a reference to the Excel Object Library in Project-References.

    This will loop through all cells 10 rows by 10 columns of the active worksheet.

    Dim oApp As Excel.Application
    Dim oSheet As Excel.Worksheet
    Dim iRow As Integer
    Dim iCol As Integer
    Set oApp = GetObject(, "Excel.Application")

    Set oSheet = oApp.ActiveSheet
    For iRow = 1 To 10
    For iCol = 1 To 10
    Debug.Print oSheet.Cells(iRow, iCol)
    'here you can compare your values with your condition and find the row
    'and col
    Next iCol
    Next iRow

    Set oSheet = Nothing
    Set oApp = Nothing




    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: selecting a certain cell in excel

    Delete the range

    Dim xlApp as new Excel.Application
    Dim xlWorkbook as Excel.Workbook
    Dim xlSheet as Excel.Worksheet
    Dim xlRange as Excel.Range

    xlApp.Visible = true

    set xlWorkbook = xlApp.Workbooks.Add

    set xlSheet = xlWorkbook.Sheets(1)

    xlSheet.Cells(9, 4) = "Hello"

    set xlRange = xlSheet.UsedRange.Find(What:="Hello")

    If Not xlRange is nothing then
    xlRange.Delete Shift:=xlUp
    End If

    xlWorkbook.Close false

    xlApp.Quit



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured