[英]Search for € symbol in a range defined in code
I am not experienced in VBA coding.我在 VBA 编码方面没有经验。
My VBA code:我的 VBA 代码:
Search = InStr(ActiveCell.NumberFormat, Chr(128))
Selection.Find(What:=Search, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
It searches and activates the cells which include the € symbol.它搜索并激活包含 € 符号的单元格。 It works only if I manually define my selection range.
只有当我手动定义我的选择范围时它才有效。
When I try inserting ActiveSheet.Range("H:H").Select
to make column H my selection (which is my goal), the code stops working.当我尝试插入
ActiveSheet.Range("H:H").Select
以使列 H 成为我的选择(这是我的目标)时,代码停止工作。
The problem is in the ActiveCell
, which is changing depending on what you are selecting.问题出在
ActiveCell
,它会根据您选择的内容而变化。 Try like this, you should get lucky:像这样尝试,你应该很幸运:
Option Explicit
Sub TestMe()
Dim Search As String
ActiveSheet.Range("H:H").Select
Search = CStr(Chr(128))
Selection.Find(What:=Search, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Select 'or .Activate
End Sub
Once you feel a bit better with recording macros, you may try to avoid ActiveSheet
, Selection
and ActiveCell
:一旦您对录制宏感觉好一点,您可以尝试避免使用
ActiveSheet
、 Selection
和ActiveCell
:
How to avoid using Select in Excel VBA 如何避免在 Excel VBA 中使用 Select
This code found the cell with the Greek Euro format in the range A1:A6
on Sheet1
in the workbook containing the code ( ThisWorkbook
).此代码在包含代码 (
ThisWorkbook
) 的工作簿中的Sheet1
上的A1:A6
范围内找到了希腊欧元格式的单元格。
The cell must hold a value (to find blanks change "*"
to ""
).单元格必须包含一个值(要查找空格将
"*"
更改为""
)。
Sub Test()
Dim rRangeToSearch As Range
Dim rFoundRange As Range
Set rRangeToSearch = ThisWorkbook.Worksheets("Sheet1").Range("A1:A6")
Application.FindFormat.Clear
Application.FindFormat.NumberFormat = "#,##0.00 [$€-408]"
Set rFoundRange = rRangeToSearch.Find(What:="*", SearchFormat:=True)
If Not rFoundRange Is Nothing Then
MsgBox "Greek Euro format found in cell " & rFoundRange.Address
End If
End Sub
No idea why [$€-408]
denotes Greek.不知道为什么
[$€-408]
表示希腊语。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.