方法1:遍历循环设置颜色,效率稍低
Sub demo()
Set Rng = ActiveWorkbook.Sheets("Sheet1").Range("$A$1:$B$3")
With Rng.Rows(1).Font
.FontStyle = "加粗"
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.Parent.Interior.Color = RGB(29, 65, 213)
End With
For i = 2 To Rng.Rows.Count
If i Mod 2 Then
With Rng.Rows(i).Interior
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.799981688894314
End With
End If
Next
End Sub
方法2:借助自定义工作簿样式,一步完成设置。
Sub demo2()
Dim Wkb As Workbook
Dim Sht As Worksheet
Dim Rng As Range
Set Wkb = ActiveWorkbook '根据实际更改
Set Sht = Wkb.Sheets("Sheet1") '根据实际更改
Set Rng = Sht.Range("$A$1:$B$3") '根据实际更改
With Wkb
With .TableStyles.Add("Pattern1")
.ShowAsAvailableTableStyle = True
With .TableStyleElements(xlHeaderRow)
.Font.FontStyle = "加粗"
.Font.ThemeColor = xlThemeColorDark1
.Font.TintAndShade = 0
End With
.TableStyleElements(xlHeaderRow).Interior.Color = RGB(29, 65, 213)
With .TableStyleElements(xlRowStripe2).Interior
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.799981688894314
End With
End With
With Sht.ListObjects.Add(xlSrcRange, Rng, , xlYes)
.Name = "Table1"
.TableStyle = "Pattern1"
.Unlist
End With
.TableStyles("Pattern1").Delete
End With
End Sub
实际运行图:
选择你想要显示那个数据的一列,单击右键选单元格格式设置的那一项,然后选择日期,挑你想要的日期格式然后确定。之后数据写到单元格会自动转化成日期格式。\x0d\x0a\x0d\x0a用代码的话,\x0d\x0a 选择单元格范围,例如:\x0d\x0a Range("A1:A9").Select\x0d\x0a 指定范围的格式\x0d\x0a Selection.NumberFormatLocal = "yyyy/m/d@"欢迎分享,转载请注明来源:内存溢出
评论列表(0条)