小编Jam*_*s H的帖子

引用Cell.Value的Excel VBA类型不匹配

嗨,很抱歉,这几乎肯定是一个“ doh”时刻,但是我已经很长时间没有编码了,所以我有点生锈。

我有一个单元格值,当我尝试将其视为字符串时,我一直遇到类型不匹配的情况,但是CStr和测试IsNull等似乎没有帮助。感谢您的一些建议。

Set ClientTable = SourceBook.Sheets("Source Data").Range("extdata")
For Each rng1 In ClientTable.Columns(1).Cells
    'if not first row (header row) and the customer name is matching the selected customer
    If (i <> 0) And (rng1.Value = SourceBook.Sheets("Source Data").Range("C1")) Then
        If Not IsNull(ClientTable.Columns(6).Cells.Offset(i, 0).Value) Then
            MsgBox ClientTable.Columns(6).Cells.Offset(i, 0).Value ' type mismatch here
        End If
        With Sheets("Contacts").Range("A1")
            .Offset(rowToWriteTo, 0).Value = ClientTable.Columns(6).Cells.Offset(i, 0).Value ' first name
            .Offset(rowToWriteTo, 1).Value = ClientTable.Columns(2).Cells.Offset(i, 0).Value ' last name
            .Offset(rowToWriteTo, 5).Value = ClientTable.Columns(3).Cells.Offset(i, 0).Value ' email
            .Offset(rowToWriteTo, 6).Value = …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

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

标签 统计

excel ×1

excel-vba ×1

vba ×1