【发布时间】:2012-11-15 19:42:19
【问题描述】:
我有一组非常大的数据,其中包括 NAS 中飞机的开始和停止时间。我想创建一个宏来在 excel 中对这些数据进行可视化表示,如下所示:
(注意:此图片使用假数据)
如您所见,我已经手动完成了前 7 行,但是有几个数据文件,每个文件多达 2500 多行,这使得这个过程很乏味。我尝试创建一个宏,但我很困惑如何搜索和选择要突出显示的适当范围。
这是我目前所拥有的:
Sub autofill()
Dim rng As Range
Dim row As Range
Dim cell As Range
'set the range of the whole search area
Set rng = Range("A2:HJ121")
For Each row In rng.Rows
Dim callsign As Variant
Set callsign = cell("contents", "A" & row)
Dim valstart As Variant
Set valstart = cell("contents", "E" & row)
Dim valstop As Variant
Set valstop = cell("contents", "F" & row)
'now select the range beginning from the column whose header matches the
'time in valstart and ends at the time which matches the time in valstop
Selection.Merge
Selection.Style = "Highlight"
Selection.Value = callsign
Next row
End Sub
选择我需要的行的最简单方法是什么?
我不是专业的程序员;如果我的代码展示了草率的技术或违反了一些神圣的编程原则,请提前道歉。 :P
谢谢!
【问题讨论】:
标签: search excel selection vba