Excel VBA查找最后一行号,其中列“C”包含一个已知的值 [英] Excel VBA Find last row number where column "C" contains a known value

查看:210
本文介绍了Excel VBA查找最后一行号,其中列“C”包含一个已知的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Excel VBA中寻求一个方法来查找列C包含已知值的最后一行号。

Seeking a method in Excel VBA to Find last row number where column "C" contains a known value.

推荐答案

将在 C 栏中找到最后

This will find the last occurrence of happiness in column C

Sub SeekHappiness()
    Dim C As Range, where As Range, whatt As String
    whatt = "happiness"
    Set C = Range("C:C")
    Set where = C.Find(what:=whatt, after:=C(1), searchdirection:=xlPrevious)
    MsgBox where.Address(0, 0)
End Sub

要仅输出行号,请使用:

To output the row number only, use:

MsgBox Mid(where.Address(0, 0), 2)

要查找第一个事件:

Sub SeekHappiness()
    Dim C As Range, where As Range, whatt As String
    whatt = "happiness"
    Set C = Range("C:C")
    Set where = C.Find(what:=whatt, after:=C(1))
    MsgBox where.Address(0, 0)
End Sub

这篇关于Excel VBA查找最后一行号,其中列“C”包含一个已知的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆