条件格式 VBA 脚本(不是 IN excel)
Conditional formatting VBA scripting (not IN excel)
我一直在开发一个脚本,该脚本 运行 通过 Txtfile 检索某些引用,将这些引用以 ('ref1','ref2','ref3',...)
的形式存储在变量中,以便在检索这些引用后我可以查询我们的数据库以从数据库中检索 10 列。
我将此结果添加到 Excel 文件中,如下所示:
If rs.BOF = False Or rs.EOF = False Then
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.workbooks.Add()
Set baseSheet = objWorkbook.worksheets(1)
fldcount = rs.Fields.count
For icol = 0 To fldcount - 1
baseSheet.Cells(1, icol + 1).VALUE = rs.Fields(icol).Name
Next
baseSheet.Range(baseSheet.Cells(1, 1), baseSheet.Cells(1, rs.Fields.count)).Font.Bold = True
baseSheet.Range("A2").CopyFromRecordset rs
objExcel.ActiveWindow.Zoom = 70
objExcel.Columns("A:J").Select
objExcel.selection.EntireColumn.AutoFit
baseSheet.Range("A2").CopyFromRecordset rs
objExcel.Visible = True
Else
MsgBox ("Geen speciale gevallen")
Exit Function
End If
Set objExcel = Nothing
Set objWorkbook = Nothing
Set baseSheet = Nothing
我的问题:我可以 运行 通过 objExcel 列 "J" 并测试一个值(if instr(contents of column "J", "400 - 700") > 0 Then
该单元格的背景颜色 = 黄色)?
我不能透露代码的其他部分,因为它们很长并且可能会泄露我的工作地点等。
要明确这不在 Excel 中,它在 IBM 终端的附件反射中。
类似的内容可能会对您有所帮助:
With ActiveSheet
For i = 1 To .Cells(.Rows.Count, "J").End(xlUp).Row
If InStr(1, .Cells(i, "J"), "400 - 700") <= 0 Then
Else
.Cells(i, "J").Interior.Pattern = xlSolid
.Cells(i, "J").Interior.PatternColorIndex = xlAutomatic
.Cells(i, "J").Interior.Color = 65535
End If
End With
我一直在开发一个脚本,该脚本 运行 通过 Txtfile 检索某些引用,将这些引用以 ('ref1','ref2','ref3',...)
的形式存储在变量中,以便在检索这些引用后我可以查询我们的数据库以从数据库中检索 10 列。
我将此结果添加到 Excel 文件中,如下所示:
If rs.BOF = False Or rs.EOF = False Then
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.workbooks.Add()
Set baseSheet = objWorkbook.worksheets(1)
fldcount = rs.Fields.count
For icol = 0 To fldcount - 1
baseSheet.Cells(1, icol + 1).VALUE = rs.Fields(icol).Name
Next
baseSheet.Range(baseSheet.Cells(1, 1), baseSheet.Cells(1, rs.Fields.count)).Font.Bold = True
baseSheet.Range("A2").CopyFromRecordset rs
objExcel.ActiveWindow.Zoom = 70
objExcel.Columns("A:J").Select
objExcel.selection.EntireColumn.AutoFit
baseSheet.Range("A2").CopyFromRecordset rs
objExcel.Visible = True
Else
MsgBox ("Geen speciale gevallen")
Exit Function
End If
Set objExcel = Nothing
Set objWorkbook = Nothing
Set baseSheet = Nothing
我的问题:我可以 运行 通过 objExcel 列 "J" 并测试一个值(if instr(contents of column "J", "400 - 700") > 0 Then
该单元格的背景颜色 = 黄色)?
我不能透露代码的其他部分,因为它们很长并且可能会泄露我的工作地点等。
要明确这不在 Excel 中,它在 IBM 终端的附件反射中。
类似的内容可能会对您有所帮助:
With ActiveSheet
For i = 1 To .Cells(.Rows.Count, "J").End(xlUp).Row
If InStr(1, .Cells(i, "J"), "400 - 700") <= 0 Then
Else
.Cells(i, "J").Interior.Pattern = xlSolid
.Cells(i, "J").Interior.PatternColorIndex = xlAutomatic
.Cells(i, "J").Interior.Color = 65535
End If
End With