VBA Excel 出报表

源数据

目标

PS:调休 以高亮颜色区分

整理一下

CMDBUT命令 VBA代码

复制代码
Private Sub CommandButton1_Click()
Dim ps As Integer
Dim pe As Integer
Dim srcs As Integer
Dim srce As Integer
Dim i As Integer
Dim j As Integer
Dim m As Integer
Dim pname As Variant
Dim pndme As Variant


ps = Range("I1").Value
pe = Range("I2").Value
srcs = Range("C1").Value
srce = Range("C2").Value

For i = ps To pe
   For j = 2 To 32
      For m = srcs To srce
      pname = Sheets("Sheet3").Range("A" & m).Value
        If pname = Range("A" & i).Value Then
        pndme = Cells(6, j).Value
            If Sheets("Sheet3").Range("B" & m).Value <= pndme And Sheets("Sheet3").Range("C" & m).Value >= pndme Then
                Cells(i, j).Value = Sheets("Sheet3").Range("D" & m).Value
                If Cells(i, j).Value = "调休" Then
                Cells(i, j).Interior.ColorIndex = 6
                End If
            End If
        End If
      Next
   Next
Next

End Sub
相关推荐
全干engineer10 小时前
Spring Boot 实现主表+明细表 Excel 导出(EasyPOI 实战)
java·spring boot·后端·excel·easypoi·excel导出
Fireworkitte10 小时前
Java 中导出包含多个 Sheet 的 Excel 文件
java·开发语言·excel
chemddd17 小时前
excel 工作需要会的
excel
醇氧19 小时前
【wps】 excel 删除重复项
excel·wps
盛夏绽放1 天前
Vue3 中 Excel 导出的性能优化与实战指南
vue.js·excel
Tomorrow'sThinker1 天前
[特殊字符] Python 自动查找替换 Excel 单元格内容 —— 高效批量处理
excel
Shipley Leo1 天前
如何在Excel中每隔几行取一行
excel
bing_1581 天前
Excel 数据透视表不够用时,如何处理来自多个数据源的数据?
excel
想要入门的程序猿1 天前
Qt写入excel
数据库·qt·excel
爱代码的小黄人2 天前
Excel VLOOKUP函数使用详解:原理、格式、常见错误与解决方案
excel