相关疑难解决方法(0)

如何在vba宏中检查空数组

我想检查空数组.Google给了我各种解决方案,但没有任何效果 也许我没有正确应用它们.

Function GetBoiler(ByVal sFile As String) As String
'Email Signature
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.ReadAll
    ts.Close
End Function

Dim FileNamesList As Variant, i As Integer
' activate the desired startfolder for the filesearch
FileNamesList = CreateFileList("*.*", False) ' Returns File names
' performs the filesearch, includes any subfolders
' present the result
' If there are Signatures then populate SigString
Range("A:A").ClearContents
For i = …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

57
推荐指数
6
解决办法
19万
查看次数

如何查找数组是否包含字符串

可能重复:
如何在MS Access VBA阵列中搜索字符串

我目前正在研究一个Excel宏,我找不到一种方法 if array.contains(mystring)

我写了以下内容,它给了我"Invaild Qualifier"的信息,并在Mainfram之后突出显示If

Dim Mainfram(4) As String

Mainfram(0) = "apple"

Mainfram(1) = "pear"

Mainfram(2) = "orange"

Mainfram(3) = "fruit"

    For Each cel In Selection
        If Mainfram.Contains(cel.Text) Then
            Row(cel.Row).Style = "Accent1"
        End If
    Next cel
Run Code Online (Sandbox Code Playgroud)

选择是一列

有人帮吗?

嗨,JP我尝试了你的建议,并说它需要对象.并突出显示 If IsInArray(cell.Text,Mainfram)然后继承 我的完整代码

Sub changeRowColor()

Columns("B:B").Select

Dim cel As Excel.Range
Dim Mainfram(4) As String

Mainfram(0) = "apple"
Mainfram(1) = "pear"
Mainfram(2) = "orange"
Mainfram(3) = "Banana"

For Each cel In Selection
    If IsInArray(cell.Value, Mainfram) …
Run Code Online (Sandbox Code Playgroud)

arrays vba substring

53
推荐指数
3
解决办法
26万
查看次数

Excel for Mac 2011:UBound()不起作用

我正在努力在Excel for Mac 2011上创建一个现有的启用宏的电子表格.

我有一个函数(Source)搜索数组的指定值:

Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
  IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
End Function
Run Code Online (Sandbox Code Playgroud)

它在Excel 2013中完美运行,但在Excel for Mac 2011上,我收到错误:

Runtime error '9': Subscript out of range
Run Code Online (Sandbox Code Playgroud)

我打破了它,发现UBound调用是造成错误的原因.

我想尽可能少地改变可维护性.如何修复Mac版本的此错误?

在此先感谢您的回复!

编辑: @Siddharth Rout的解决方案很明显,但由于我在循环中搜索数组,我不得不修改循环以在每次迭代之间重置数组,如下所示(如果其他人遇到同样的问题!):

' --- START Reset Array for OS X ---
Dim OS_X_Hack(99) As String

For intIndex = 0 To 99
    OS_X_Hack(intIndex) = Original(intIndex)
Next

Erase Original()
ReDim Original(0 To 99) As String

For intIndex = 0 To 99
    Original(intIndex) …
Run Code Online (Sandbox Code Playgroud)

arrays excel vba excel-vba excel-vba-mac

5
推荐指数
1
解决办法
1613
查看次数

添加到数组并在数组中查找值

我有2个数组:一个具有搜索文档的值为(arr),另一个将使用找到的值(arr2)放入相关的单元格地址.我没有问题arr,并在我的代码中成功使用它.

有了arr2,我想找到包含值的任何单元格,arr并将单元格地址lRow的行数向下添加到arr2,但仅限于该地址尚未包含在内arr2.

为了解决我的问题,我找到了2个我想要结合的答案,但到目前为止还没有运气.

Excel VBA - 在数组末尾添加元素

如何在数组中搜索字符串

我的代码如下:

Sub Initiate()

Dim arr(3) As Variant
    arr(0) = "Value1"
    arr(1) = "Value2"
    arr(2) = "Value3"
    arr(3) = "Value4"
Dim arr2() As Variant
Dim Alc as String
Dim lRow as Long
Dim fVal as String

lRow = Activesheet.Cells(Activesheet.Rows.Count, 1).End(xlUp).Row

For Each element In arr

fVal = element

Set fRange = WA.Cells.Find(What:=fVal, LookIn:=xlFormulas _
    , LookAt:=xlPart, SearchOrder:=xlByRows, …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

4
推荐指数
1
解决办法
149
查看次数

标签 统计

vba ×4

excel ×3

excel-vba ×3

arrays ×2

excel-vba-mac ×1

substring ×1