0

I'm a new VB.net user (and completely self taught).

I'm trying to search down column A of an excel workbook (starting at "A1") to check the cell contents. On finding a specific value, I want to msgbox out which cell it is in.

Can anybody help me in how to code this please.

pbuffh
  • 9
  • 2
  • I think you want a For...Next or For Each then an Exit For. Try some code and come back with your code if it doesn't work as expected. Show us your attempt. – Mary Jul 13 '18 at 00:28
  • Or you could use the Excel workbook function `INDEX`/`MATCH`. – AJD Jul 13 '18 at 06:47
  • Please see: [Why is “Can someone help me?” not an actual question?](http://meta.stackoverflow.com/q/284236) – Chris Dunaway Jul 13 '18 at 18:26

1 Answers1

0

Having played with various things over the day, I've finally got it to work!!!

How I've done it - it seems simple now I've worked it out:

    Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet

    ' For the first sheet in an excel workbook
    xlWorkSheet = CType(objApp.Sheets(1), Microsoft.Office.Interop.Excel.Worksheet)
    Dim strSheetName As String = xlWorkSheet.Name

    ' ***** Find the row with "Ambient Temp (C)" as its header
    AmbientRange = objAppDeckCalc.Worksheets(strSheetName).Range("a1")
    TempValue = AmbientRange.Value

    Do While TempValue <> "Ambient Temp (C)"
        AmbientRange = AmbientRange.Offset(1, 0)

        TempValue = AmbientRange.Value

        CountRow = CountRow + 1
        If CountRow = 100 Then
            MsgBox("Fields Not Named Correctly!")
            End
        End If
    Loop

    MsgBox("Ambient Temp (C) - CountRow - " & CountRow)
pbuffh
  • 9
  • 2