Java vbnullstring,使用查找/替换清除vbNullString

本文探讨了Excel中看似空白但实际并非空的单元格问题,这些单元格在公式中无法被ISBLANK函数识别为真空白。作者遇到了在排序时这些假空白单元格会出现在顶部而非底部的问题。为解决此问题,尝试了多种方法,包括使用VBA循环清除,但因数据量大导致效率低下。最后,提供了一段代码,通过设置单元格格式和值来清除这些假空白单元格,但代码未达到预期效果。
摘要由CSDN通过智能技术生成

I have a spreadsheet that is generated as a report in our Enterprise system and downloaded into an Excel spreadsheet. Blank cells in the resulting spreadsheet are not really blank, even though no data is present - and the blank cells do Not contain a 'space' character.

For example, the following cell formula in A2 returns TRUE (if A1 is a blank cell):

=IF(A1="","TRUE","FALSE")

However,

=ISBLANK(A1)

returns FALSE.

You can replicate this problem by typing an apostrophe (') in a cell and copying the cell. Then, use Paste Special...Values to paste to another cell and the apostrophe is not visible in the pasted cell, nor in the Formula Bar. There appears to be a clear cell, but it will evaluate to FALSE using ISBLANK.

This causes sorting to result in the fake blank cells at the top of an ascending sort, when they need to be at the bottom of the sort.

I can use a vba loop to fix the fake blanks, to loop through every column and evaluate

IF Cell.VALUE = "" Then

Cell.Clear

but because the spreadsheet has tens of thousands of rows of data and as many as 50 columns, this adds substantial overhead to the program and I would prefer to use FIND and Replace.

Here is the code that does not currently work:

Range("ZZ1").Copy

Range("Table1[#All]").Select

With Selection

.Replace What:="", Replacement:=.PasteSpecial(xlPasteValues, xlNone, False, False), _

LookAt:=xlWhole, SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False

End With

The following things do not work to clear the fake blank cells either:

Replacement:= vbnullstring

Replacement:= ""

Replacement:= Cells.Clear

Replacement:= Cells.ClearContents

Replacement:= Cells.Value = ""

I have tried 20 other things that do not work either.

解决方案

Try this

With ActiveSheet.UsedRange

.NumberFormat = "General"

.Value = .Value

End With

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值