[英]Use numbered column references in Excel Conditional Formatting code in VBA script
I have some VBA script that applies some conditional formatting in Excel.我有一些 VBA 脚本在 Excel 中应用了一些条件格式。
Is there a way that I can reference the number values of the columns instead of the normal cell reference.有没有一种方法可以引用列的数值而不是普通的单元格引用。
This is what I currently have:这是我目前拥有的:
"=AND(NOT(ISBLANK(F3)),F3<>""SomeValue1"",F3<>""SomeValue1"")"
And this is the sort of thing I would like to achieve:这就是我想要实现的目标:
"=AND(NOT(ISBLANK(Cells(3,6))),Cells(3,6)<>""SomeValue1"",Cells(3,6)<>""SomeValue2"")"
Replace("=AND(NOT(ISBLANK({addr})),{addr}<>""SomeValue1"",{addr}<>""SomeValue2"")", _
"{addr}", Cells(3,6).Address)
I was able to resolve my query using the following code to first convert the column number into a column letter:我能够使用以下代码解析我的查询,首先将列号转换为列字母:
ColLetter = Split(Cells(1, ColNumber).Address, "$")(1)
Once I had this conversion value I was able to use this variable in my code for conditional formatting:一旦我有了这个转换值,我就可以在我的代码中使用这个变量来进行条件格式化:
"=AND(NOT(ISBLANK(" & ColLetter & "3))," & ColLetter & "3<>""SomeValue1""," & ColLetter & "3<>""SomeValue1"")"
Thanks to everyone whop responded.感谢所有回复的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.