热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在列表中查找值的第一个实例-Findthefirstinstanceofavalueinalist

Thiscode:RPName_rngCells.Find(What:RPName,SearchOrder:xlByRows,_SearchDirection:xlPr

This code:

RPName_rng = Cells.Find(What:=RPName, SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious).Row

gives me the last instance of a value in a list. It works well. I need to find the first instance of that value instead of the last and then use that as the top left anchor of a range to be named.

给我列表中值的最后一个实例。它运作良好。我需要找到该值的第一个实例而不是最后一个,然后使用它作为要命名的范围的左上角锚点。

Thanks for your help.

谢谢你的帮助。

2 个解决方案

#1


3  

Give this a try:

尝试一下:

Option Explicit

Sub dural()
    Dim RPName As String, RPName_rng As Long
    RPName = "happiness"
    RPName_rng = Cells.Find(What:=RPName, After:=Cells(1, 1), _
        SearchOrder:=xlByRows).Row
    MsgBox RPName_rng
End Sub

This will find the first occurrance.

这将找到第一次出现。

#2


0  

you could use just the "RPName_rng = Cells.Find(What:=RPName)" part. The search goes from the 1st cell in the search range ("cells" in your case, meanning "everywhere"). All you need to do is to first check if the "Cells(1)=RPName" in case it's in the first cell.

你可以只使用“RPName_rng = Cells.Find(What:= RPName)”部分。搜索从搜索范围中的第一个单元格开始(在您的情况下为“单元格”,意味着“无处不在”)。您需要做的就是首先检查“Cells(1)= RPName”是否在第一个单元格中。


推荐阅读
author-avatar
死神邀请我
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有