Domanda

I am new in VBA. How can identify a cell that crosses with a row containing text "This Row" and a column containing text "This Column" and set the content of it as integer called MyContent? This should be searched in a range of 1000 rows and 50 columns starting from A1.

È stato utile?

Soluzione

Try this one:

Sub test()
    Dim rngCol As Range, rngRow As Range
    Dim myContent As Integer

    With ThisWorkbook.Worksheets("Sheet1")
        Set rngCol = .Cells.Find(What:="This Column", LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
        Set rngRow = .Cells.Find(What:="This Row", LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)

        If rngRow Is Nothing Or rngCol Is Nothing Then
            MsgBox "Cell with text 'This Row' in row and with text 'This Column' in column not found"
            Exit Sub
        End If

        myContent = .Cells(rngRow.Row, rngCol.Column).Value
    End With
End Sub
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top