在一个EXCEL表的某一列中查找一个特定的值,并返回这个单元格的位置,VB代码如何实现?

解决方案 »

  1.   

    Private Function FindPos(intColumn As Integer, strContent As String) As Integer
    Dim i As Integer
    i = 1
    Do While i < 30000
        If CStr(ThisWorkbook.ActiveSheet.Cells(i, intColumn)) = strContent Then
            FindPos = i
            Exit Do
        End If
        i = i + 1
    LoopEnd FunctionPublic Sub s()
    MsgBox FindPos(1, "a")
    End Sub
      

  2.   

    Private Function FindPos(intColumn As Long, strContent As String) As Integer
    Dim i As long
    i = 1
    Do While i < 200000'这下满足了吧
        If CStr(ThisWorkbook.ActiveSheet.Cells(i, intColumn)) = strContent Then
            FindPos = i
            Exit Do
        End If
        i = i + 1
    LoopEnd FunctionPublic Sub s()
    MsgBox FindPos(1, "a")'1是第一列,a是特定数据
    End Sub
      

  3.   

    楼上兄弟是在坑人么..那会慢死..用什么函数忘记了,LZ去查一下OFFICE里自带的VBA帮助,里面有,你可以直接调用它内置的一个函数来查询.
      

  4.   

    这就是宏里面记录的东西
    找文字
        Range("C1").Select
        ActiveCell.FormulaR1C1 = "=MATCH(""要找的字符串"",C[2],0)"
        Debug.Print "单元格位置:"; ActiveCell.Value
    找数字
        Range("C1").Select
        ActiveCell.FormulaR1C1 = "=MATCH(9,C[2],0)"
        Debug.Print "单元格位置:"; ActiveCell.Value