【发布时间】:2018-01-27 14:17:19
【问题描述】:
(编码新手发布第一个问题,请原谅我的错误)
我正在尝试学习简单的数据验证方法。我读了另一篇与我正在做的类似的帖子:convert-entire-range-to-uppercase,,但是当我更改范围以满足我的需要时它不起作用。找不到其他解决此问题的方法。
我有一个名为“块”的 Excel 列,它出现在不同工作簿的不同位置,我需要将该列中出现的所有字母大写。我认为代码按预期工作,直到最后一行,这导致“#NAME?”填充整个范围。
这是我目前所拥有的:
Dim LastColumn As Long
Dim LastRow As Long
Dim BlockColumn As Long
Dim BlockRange As Range
'defines LastColumn, LastRow & BlockColumn
LastColumn = Cells.Find(What:="*", After:=Range("a1"), LookAt:=xlPart, LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Column
LastRow = Cells.Find(What:="*", After:=Range("a1"), LookAt:=xlPart, LookIn:=xlFormulas, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
BlockColumn = Cells.Find(What:="Block", After:=Range("a1"), LookAt:=xlPart, LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Column
'capitalizes any text in BlockColumn
Set BlockRange = Range(Cells(2, BlockColumn), Cells(LastRow, BlockColumn))
BlockRange = [UPPER(BlockRange)]
除了想知道我在哪里犯了错误之外,我确信我把这件事弄得太复杂了。有人可以告诉我一种重新思考或简化它的方法吗?我也想知道通过循环(而不是这种方法)完成这样的任务的一般利弊,但不确定这是否是问这个的地方......
【问题讨论】:
标签: excel vba dynamic range uppercase