在范围内按行和列内容查找单元格,并将其设置为整数



我是vba中的新手。如何识别一个与包含文本"此行"的行交叉的单元格和包含文本"此列"的列并将其设置为整数称为mycontent的单元格?应从A1开始以1000行和50列的范围进行搜索。

尝试这个:

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

最新更新