excel - 在excel中用特定颜色填充偶数行
问题描述
我需要在我的工作表中有交替行是特定颜色 RGB(142、169、219)。我使用了 =MOD(ROW(),2)=0 但我的代码在运行时的方式是 .clear 它会删除这些行中的颜色。我试图在.clear 之后和ActiveWorkbook.Save 之前重新应用它的代码。此宏仅在月份更改为下个月时删除,它设置为在打开 excel 文件时运行和检查。我不想在 G1 的电子表格中使用 mthNum 来检查当前月份,但我对 VBA 还是很陌生,想不出其他方法。宏
Sub MakeNewSheet()
Dim mthNum As Integer
Dim name As String
todaydate = Format(Date, "MM/DD/YYYY")
mthNum = Month(todaydate)
name = MonthName(mthNum)
yearNum = Year(todaydate)
pdfname = "Jobs_" & name & yearNum
If Range("G1").Value = "" Then Range("G1") = mthNum
If Range("G1") <> mthNum Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\Users\******\Documents\*******\Desktop\" & pdfname
ThisWorkbook.Sheets("Sheet1").Range("A2:F3000").Clear
ThisWorkbook.Sheets("Sheet1").Range("G1").Value = mthNum
ActiveWorkbook.Save
End If
End Sub
工作表
Dim mthNum As Integer
todaydate = Format(Date, "MM/DD/YYYY")
mthNum = Month(todaydate)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("G1")) Is Nothing Then
MsgBox ("This Number Cannot Be Changed!")
Target.Offset(1, -6).Activate
End If
End If
Dim nPut As String
If ThisWorkbook.Sheets("Sheet1").Range(Cells(Selection.Row, 4).Address) <> "" Then GoTo 16
If Selection.Count = 1 Then
If Not Intersect(Target, Range("D:D")) Is Nothing Then
nPut = InputBox("Please Scan Part Number")
If nPut <> "" Then
Target.Value = nPut
Target.Offset(0, 1).Activate
End If
End If
End If
Dim nPut2 As String
16 If ThisWorkbook.Sheets("Sheet1").Range(Cells(Selection.Row, 5).Address) <> "" Then Exit Sub
If ThisWorkbook.Sheets("Sheet1").Range(Cells(Selection.Row, 4).Address) = "" Then Exit Sub
If Selection.Count = 1 Then
If Not Intersect(Target, Range("E:E")) Is Nothing Then
nPut2 = InputBox("Please Scan Badge")
If nPut2 <> "" Then
Target.Value = nPut2
If ThisWorkbook.Sheets("Sheet1").Range(Cells(Selection.Row, 6).Address) = "" Then ThisWorkbook.Sheets("Sheet1").Range(Cells(Selection.Row, 6).Address) = todaydate
Target.Offset(1, -4).Activate
End If
Else
Exit Sub
End If
End If
End Sub
解决方案
推荐阅读
- loops - SSIS foreach 循环枚举器 empty 为空 - 仅在部署时
- makefile - *.c 在依赖 xh 更改时不会反抗,使用自动生成的 *.d 文件
- tfs - Azure Devops - 是否可以防止复制或克隆工作项
- node.js - TypeError [ERR_UNESCAPED_CHARACTERS] 请求路径包含非转义字符
- css - 行跨度未在全日历中应用
- python-3.x - Python 3.7 Flask-SocketIO + uWSGI + nginx 配置
- powershell-3.0 - 5 台机器中有 1 台无法使用 Invoke-Command 共享权限
- r - r lm 参数估计
- mjpeg - 如果文件中定义了 MJPEG 帧速率,该怎么办?
- mongodb - 如何将 mongodb 会话放入 creachadair/jrpc2 处理程序中