Excel精英培训网

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

[已解决]修改精简代码,当整行无数据时去掉该行边框

[复制链接]
发表于 2017-2-11 15:02 | 显示全部楼层 |阅读模式
  1. Sub 内虚外实()
  2. myr = Range("b100").End(xlUp).Row
  3. With Range("b4:L" & myr + 2)
  4.    .Borders.Weight = xlThin
  5.    .Borders(xlEdgeLeft).LineStyle = xlContinuous '左
  6.    .Borders(xlEdgeRight).LineStyle = xlContinuous '右
  7.    .Borders(xlEdgeTop).LineStyle = xlContinuous '上
  8.    .Borders(xlEdgeBottom).LineStyle = xlContinuous '下
  9.    .Borders(xlInsideHorizontal).LineStyle = xlContinuous '内横线
  10.    .Borders(xlInsideHorizontal).Weight = xlHairline '最细线
  11.    .Borders(xlInsideVertical).LineStyle = xlContinuous '内竖线
  12.    .Borders(xlInsideVertical).Weight = xlHairline
  13. End With
  14. End Sub
复制代码
谢谢各位老师的帮助!

最佳答案
2017-2-13 15:03
Sub FillFormat()
    Dim i
    i = [B65536].End(xlUp).Row
    Range("B7:L7").AutoFill Destination:=Range("B7:L" & (i + 2)), Type:=xlFillFormats
    Range(Cells(i + 3, "b"), [L65536]).ClearFormats
End Sub



利用已有单元格,填充格式。
最后一句清除不需要格式的区域

有数据单元格边框虚实线(VBA).rar

26.42 KB, 下载次数: 4

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2017-2-13 15:03 | 显示全部楼层    本楼为最佳答案   
Sub FillFormat()
    Dim i
    i = [B65536].End(xlUp).Row
    Range("B7:L7").AutoFill Destination:=Range("B7:L" & (i + 2)), Type:=xlFillFormats
    Range(Cells(i + 3, "b"), [L65536]).ClearFormats
End Sub



利用已有单元格,填充格式。
最后一句清除不需要格式的区域

评分

参与人数 1 +3 收起 理由
feiaoli + 3 我和小伙伴都惊呆了

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-27 07:12 , Processed in 0.414931 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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