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

使用excelvba宏搜索并找到列标题-searchandlocateacolumnheaderusingexcelvbamacro

Ihaveaworksheetthatisupdatedregularly.Thereforethecolumnheaderpositionschangeregurlary

I have a worksheet that is updated regularly. Therefore the column header positions change regurlary. For example if today "Date" is in column J1 as the column header, tomorrow "Date" could be in column C1. Therefore if I want to perform sorting operations, using a macro for date, I cannot refer to it using a hard-coded cell reference for example

我有一个定期更新的工作表。因此列标题位置改变了regurlary。例如,如果今天“Date”在列J1中作为列标题,则明天“Date”可以在列C1中。因此,如果我想执行排序操作,使用宏作为日期,我不能使用硬编码的单元格引用来引用它,例如

cu.Range("J1").AutoFilter Field:=10, Criteria1:=">=" & Date

Is there a way in excel to search and locate a column header for example date. So that after I locate, I can perform the sorting based on current date.

有没有办法在Excel中搜索和查找列标题,例如日期。因此,在找到之后,我可以根据当前日期执行排序。

How can this be performed through a macro?

如何通过宏执行此操作?

1 个解决方案

#1


3  

You can use the Find method to do this. Example:

您可以使用Find方法执行此操作。例:

Dim rngDateHeader As Range
Dim rngHeaders As Range
Set rngHeaders = Range("1:1") 'Looks in entire first row; adjust as needed.
Set rngDateHeader = rngHeaders.Find("Date")

You would then use rngDateHeader instead of the hard-coded Range("J1").

然后,您将使用rngDateHeader而不是硬编码范围(“J1”)。


推荐阅读
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社区 版权所有