VBA Excel 出报表

[复制链接]
发表于 2026-1-25 04:45:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
源数据

目标 

PS:"调休" 以高亮颜色区分
整理一下

CMDBUT下令  VBA代码
  1. Private Sub CommandButton1_Click()
  2. Dim ps As Integer
  3. Dim pe As Integer
  4. Dim srcs As Integer
  5. Dim srce As Integer
  6. Dim i As Integer
  7. Dim j As Integer
  8. Dim m As Integer
  9. Dim pname As Variant
  10. Dim pndme As Variant
  11. ps = Range("I1").Value
  12. pe = Range("I2").Value
  13. srcs = Range("C1").Value
  14. srce = Range("C2").Value
  15. For i = ps To pe
  16.    For j = 2 To 32
  17.       For m = srcs To srce
  18.       pname = Sheets("Sheet3").Range("A" & m).Value
  19.         If pname = Range("A" & i).Value Then
  20.         pndme = Cells(6, j).Value
  21.             If Sheets("Sheet3").Range("B" & m).Value <= pndme And Sheets("Sheet3").Range("C" & m).Value >= pndme Then
  22.                 Cells(i, j).Value = Sheets("Sheet3").Range("D" & m).Value
  23.                 If Cells(i, j).Value = "调休" Then
  24.                 Cells(i, j).Interior.ColorIndex = 6
  25.                 ELSE
  26.                 Cells(i, j).Interior.ColorIndex = 1
  27.                 End If
  28.             End If
  29.         End If
  30.       Next
  31.    Next
  32. Next
  33. End Sub
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表