开发者

Conditional formatting of a column based off having any text in the first column of the same row

开发者 https://www.devze.com 2023-04-06 15:35 出处:网络
I\'m not sure if this is even possible without going to VB, but I was trying to do it through conditional formatting.Basically I have a column (Column K) that will a开发者_Go百科lways be the same valu

I'm not sure if this is even possible without going to VB, but I was trying to do it through conditional formatting. Basically I have a column (Column K) that will a开发者_Go百科lways be the same value (345) if there is a record entered in that row. Basically when I populate my reports I simply want the value (345) to be entered into Column K if there is any data in that row. I was trying to just use Column A as a reference. I was messing with =IF(ISTEXT(Col.A location),"345","") but that's getting nowhere. So, I'm looking for ideas outside of vba, but if there are no possibilities then vba is the way to go I suppose. :)


Assuming your data is in columns A to J, and that it starts in row 2, enter this in K2 and copy down as necessary:

=IF(COUNTA(A2:J2),345,"")

Edit: For a conditional formatting formula you don't need the "If" part, because the formatting is already ... conditional:

=COUNTA(A2:J2)


Will this work?

=IF(ISBLANK(A1),"","345")


This code works to tell whether column A has something in it or not COUNTA(INDIRECT("$A$"&ROW()))>0, but I don't think you can set the value of the cell using conditional formatting. But with conditional formatting you have to know ahead of time how far down your data is going to go unless you just put it in all the rows.

Why don't you just put it in your VBA code when you are copying, you can find out what the last row is then put the IF() formula in. You can use this code:

Dim r1 As Range
Set r1 = Range("K1")
r1.NumberFormat = "General"
r1 = "=IF(COUNTA(INDIRECT(""$A$""&ROW())>0,""345"","""")"
r1.AutoFill Destination:=Range(r1, r1.Offset(200))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号