Excel精英培训网

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

[VBA] 分享一个简单的工作计划表

[复制链接]
发表于 2018-4-23 12:53 | 显示全部楼层 |阅读模式



代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$D$2" And Target.Count <> 1 Then
   Exit Sub
Else
   Application.ScreenUpdating = False
   Dim a(1 To 6) As Integer
   Dim i As Integer
   Dim DayCount As Integer
   i = 1
   Rows("4:34").Hidden = False
   Range("b4:b34").UnMerge
   Range("e4:e34").UnMerge
With Range("b4:h34")
   .Borders.LineStyle = xlContinuous
   .Borders.Weight = xlMedium
   .Borders(xlInsideVertical).LineStyle = xlContinuous
   .Borders(xlInsideVertical).Weight = xlHairline
   .Borders(xlInsideHorizontal).LineStyle = xlContinuous
   .Borders(xlInsideHorizontal).Weight = xlHairline
End With
DayCount = Day(DateSerial(Sheets("para").[a2], Range("d2") + 1, 0))
For Each rng In Range("c4:c34")
    If Weekday(rng.Value, 2) = 1 Then
    a(i) = rng.Row
    i = i + 1
    End If
Next
If a(1) <> 4 Then
Range("b4", "b" & a(1) - 1).Merge
Range("e4", "e" & a(1) - 1).Merge
End If
For j = 1 To i - 2
  Range("b" & a(j), "b" & a(j + 1) - 1).Merge
  Range("e" & a(j), "e" & a(j + 1) - 1).Merge
Next
Range("b" & a(i - 1), "b" & DayCount + 3).Merge
Range("e" & a(i - 1), "e" & DayCount + 3).Merge


If DayCount <> 31 Then Rows(DayCount + 4 & ":" & 34).Hidden = True
Application.ScreenUpdating = True
End If
End Sub

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2021-6-27 00:21 | 显示全部楼层
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-30 20:07 , Processed in 0.585672 second(s), 5 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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