excel - IsNumeric 函数对于空单元格返回 true

标签 excel acrobat isnumeric vba

我运行一个宏,从 PDF 文件复制表格并将其保存在 Excel 中。 一些表格包含空单元格,在我的分析中,我需要知道空单元格的数量。 我有一个函数可以遍历每一列来检查该单元格中的值是否为数字。 问题是当我在空单元格上运行这个函数时它返回 true。我什至尝试使用 Isblank() 函数手动检查单元格,它返回“false”。 (如果我在粘贴范围之外的任何单元格上尝试此操作,它将返回“true”)

我猜测当我从 PDF 中复制并粘贴内容时,它会以某种方式为空单元格粘贴一些值。

有人遇到过类似的问题吗?如果是这样,有什么解决办法吗?

如果有任何帮助,这里是我用来复制和粘贴的代码

'Initialize Acrobat by creating App object
Set PDFApp = CreateObject("AcroExch.App")

'Set AVDoc object
Set PDFDoc = CreateObject("AcroExch.AVDoc")

'Open the PDF
If PDFDoc.Open(PDFPath, "") = True Then
    PDFDoc.BringToFront

    'Maximize the document
    Call PDFDoc.Maximize(True)

    Set PDFPageView = PDFDoc.GetAVPageView()

    'Go to the desired page
    'The first page is 0
    Call PDFPageView.GoTo(DisplayPage - 1)

    '-------------
    'ZOOM options
    '-------------
    '0 = AVZoomNoVary
    '1 = AVZoomFitPage
    '2 = AVZoomFitWidth
    '3 = AVZoomFitHeight
    '4 = AVZoomFitVisibleWidth
    '5 = AVZoomPreferred

    'Set the page view of the pdf
    Call PDFPageView.ZoomTo(2, 50)

End If

Set PDFApp = Nothing
Set PDFDoc = Nothing

On Error Resume Next

'Show the adobe application
PDFApp.Show

'Set the focus to adobe acrobat pro
AppActivate "Adobe Acrobat Pro"

'Select All Data In The PDF File's Active Page
SendKeys ("^a"), True

'Right-Click Mouse
SendKeys ("+{F10}"), True

'Copy Data As Table
SendKeys ("c"), True

'Minimize Adobe Window
SendKeys ("%n"), True

'Select Next Paste Cell
Range("A" & Range("A1").SpecialCells(xlLastCell).Row).Select
'Cells(1, 1).Select
'Paste Data In This Workbook's Worksheet
ActiveSheet.Paste

最佳答案

在某些情况下,最好检查 length单元格内的字符而不是使用 isNumeric(),或检查错误等...

例如尝试以下代码

它建立事件工作表中使用的范围,然后迭代检查每个单元格的长度 (len())

您可以在 VBE 中查看立即窗口 CTRL+G 来查看哪些单元格地址为空 等到宏执行完毕,您将看到一个消息框,说明范围内有多少个空单元格

Option Explicit

Sub CheckForEmptyCells()

    Dim lastCol As Range
    Set lastCol = ActiveSheet.Cells.Find(What:="*", After:=ActiveSheet.Cells(1, 1), LookIn:=xlFormulas, _
              LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)

    Dim rng As Range
    Set rng = Range("A1:" & lastCol.Address)

    Dim cnt As Long
    cnt = 0

    Dim cell As Range
    For Each cell In rng
        If Len(cell) < 1 Then
            Debug.Print cell.Address
            cnt = cnt + 1
        End If
    Next

    MsgBox "there are " & cnt & " empty cells within the range " & rng.Address
End Sub

finished

关于excel - IsNumeric 函数对于空单元格返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18225497/

相关文章:

c# - 在 VSTO 的 Excel get_Range 中使用的正确分隔符

excel - 在 Excel VBA 中复制筛选的数据

c++ - 如何将击键发送到 C++ 中的应用程序

c# - 如何使用带有 C# 或 VB.NET 的 Acrobat SDK 从文件创建 PDF?

asp-classic - IsNumeric 函数无法正常工作

jQuery:限制 "number"文本框的唯一输入的最佳方法是什么? (允许小数点)

asp.net - 使用 Excel VBA 打开 IE 并与 Web 表单交互

vba - 如何通过 Excel VBA 使用 Mozilla Thunderbird 生成和发送电子邮件

pdf - 仅打印 PDF 的上半部分 - 在纸张的上半部分

javascript - 改进的 isNumeric() 函数?