Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 784|回复: 9

[已解决]删除空单元格并上移

[复制链接]
发表于 2022-5-26 18:35 | 显示全部楼层 |阅读模式
删除空单元格并上移 求助代码

最佳答案
2022-5-27 15:10


請測試看看,謝謝

Sub test()
Dim xD, xR As Range, xU As Range
Application.ScreenUpdating = False
Set xD = CreateObject("Scripting.Dictionary")
For Each xR In Range(Cells(Rows.Count, 1).End(3), [a1])
    If xR <> "" Then GoTo 99
    If xU Is Nothing Then Set xU = xR Else Set xU = Union(xR, xU)
99: Next
If Not xU Is Nothing Then xU.EntireRow.Delete
Application.ScreenUpdating = True
End Sub

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2022-5-26 19:46 | 显示全部楼层
CTRL+G定位空值。右键 。。删除,选择上移,就可以了。
回复

使用道具 举报

 楼主| 发表于 2022-5-26 21:39 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2022-5-27 10:21 | 显示全部楼层
回复

使用道具 举报

发表于 2022-5-27 10:51 | 显示全部楼层

可以附上檔案,避免解讀有誤,謝謝
回复

使用道具 举报

发表于 2022-5-27 13:22 | 显示全部楼层
'
Dim endrow As Single

Dim K As Single


endrow = Range("a65535").End(xlUp).Row



    For K = 2 To endrow
   

    If Cells(K, 2).Value = "0" And Cells(K, 3).Value = "0" And Cells(K, 5).Value = "0" And Cells(K, 6).Value = "0" Then             '如果单元格为空白


    Rows(K).Delete

K = K - 1


    End If


    Next K




回复

使用道具 举报

 楼主| 发表于 2022-5-27 14:43 | 显示全部楼层
咋不行呢?

新建 M.zip

12.79 KB, 下载次数: 4

回复

使用道具 举报

发表于 2022-5-27 15:10 | 显示全部楼层    本楼为最佳答案   


請測試看看,謝謝

Sub test()
Dim xD, xR As Range, xU As Range
Application.ScreenUpdating = False
Set xD = CreateObject("Scripting.Dictionary")
For Each xR In Range(Cells(Rows.Count, 1).End(3), [a1])
    If xR <> "" Then GoTo 99
    If xU Is Nothing Then Set xU = xR Else Set xU = Union(xR, xU)
99: Next
If Not xU Is Nothing Then xU.EntireRow.Delete
Application.ScreenUpdating = True
End Sub

回复

使用道具 举报

发表于 2022-5-27 17:22 | 显示全部楼层
Range("A1:A20").SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
回复

使用道具 举报

 楼主| 发表于 2022-5-28 01:17 | 显示全部楼层
謝謝
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-20 22:52 , Processed in 0.342727 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表