简体   繁体   English

(Excel 2013 / Non-VBA)格式数据列基于其他单元格的值吗?

[英](Excel 2013/Non-VBA) Format Data column based on value of another cell?

We have a column that is query driven, and the query partially formats the values in the column using math based off the value of a "user entry cell" on another sheet. 我们有一个由查询驱动的列,查询根据另一张纸上“用户输入单元格”的值,使用数学运算对该列中的值进行部分格式化。

For the really curious, our query looks like this: 对于真正好奇的人,我们的查询如下所示:

DECLARE @rotationsNum INT
SET @rotationsNum = ?
SELECT  t.Piece_ID, t.Linear_Location, ((ROW_NUMBER() OVER(ORDER BY 
Linear_Location) -1 )%@rotationsNum )*(360/@rotationsNum) AS Rotation FROM 
(SELECT Position.Feature_Key, Piece_ID, ((Place-1)%(Places/@rotationsNum))+1 AS Linear_Location, Place, Measured_Value, Places FROM Fake.dbo.Position LEFT JOIN Fake.dbo.Features 
ON Position.Feature_Key = Features.Feature_Key WHERE Position.Inspection_Key_FK = (SELECT Inspection_Key FROM Fake.dbo.Inspection WHERE Op_Key = ?)) AS t 
ORDER BY Piece_ID, Linear_Location

The first parameter "@rotationsNum" is a cell that will always have a value between 1-4. 第一个参数“ @rotationsNum”是一个单元格,其值始终在1-4之间。 IF the value is 1, the entire column will show "0"s, which we want to show as "N/A". 如果该值为1,则整列将显示为“ 0”,我们希望将其显示为“ N / A”。 However, it isn't as simple as "How to hide zero data.." Because if the "@rotationsNum" == 2, 3, or 4, there will still be 0 values in the column that need to be shown. 然而,它不是那么简单的“如何隐藏零数据..”因为如果“@rotationsNum” == 2,3,或4,仍然会有在列0的值需要被示出。

A "@rotationsNum" value of 2 will have the query write the column as such: example “ @rotationsNum”值为2时,查询将这样写列: 示例

So I am trying to come up with a way to format the column =IF(cell>1, do nothing, overwrite entire column to say "NA"). 因此,我尝试提出一种格式化列= IF(cell> 1,什么也不做,覆盖整个列,说“ NA”)的方法。 But I don't think it is that straight forward since the column is query driven. 但是我不认为这是直接的,因为该列是查询驱动的。

My resolution was to format the column so that if the cell that drives the "@rotationsNum" parameter is below 2, then the whole column just gets "grayed out". 我的解决方法是格式化该列,以便如果驱动“ @rotationsNum”参数的单元格小于2,则整个列只会“变灰”。 It kind of makes it look like a redaction, and isn't as desirable as "NA", but it works for our purposes. 它有点像编辑,不如“ NA”理想,但可以满足我们的目的。 Hopefully this solution helps someone else who stumbles upon this problem. 希望此解决方案可以帮助其他偶然发现此问题的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM