简体   繁体   中英

Excel formatting without VBA

So I have some results which may or may not have totals. In this case food. Each food is given an amount and a weight total. I have information below the results however which I do not want to shift. I would use a table however, if I hide rows, it shifts items up. If I sort the rows, the name of the food with no results will still show. Any idea how I could reformat my results into food with results only in a new referenced cell? I'm trying to automate this with no button pressing, and without using macro's/vba's. I could use something like =IF(ISBLANK(B21),"noResults",A21) but how could i list them all like my example blelow?

       a1    b1      c1 

           Amount   Weight
x    Apples   5     10
x    Oranges        
x    Peaches  6     10
x    Lemons   2     10
x    Tomatos        
x    Avacados 3     10
x
x
x    xxxxdon't shift or move xxxxxxxxx

TO:

x    g1      h1     i1
x            Amount Weight
x    Apples   5     10
x    Peaches  6     10
x    Lemons   2     10  
x    Avacados 3     10
x
xxxxxxxxdon't shift or move xxxxxxxxx

If you can add an ID column to the foods, you could do the following using the SMALL() function:

在Excel中使用small()函数的示例

=IF(D3<>"",B3,"")
=IFERROR(SMALL($F$3:$F$8,ROW(C1)),"")
=VLOOKUP(H3,$B$3:$F$8,2,FALSE)

To Explain Further

  • The SMALL() function takes an array of numbers and will return the 1st smallest, 2nd smallest, or whatever smallest number you specify. Because this example only has Food names, I had to add an ID column (column B) to get an array of numbers.

  • Since we only want to view rows with data (amount & weight), I added another column ID Formula (column F) to only display the ID if the column has data.

  • Now that we are only displaying ID's with data, we can use the SMALL() function to get the 1st smallest ID still showing, then the 2nd smallest ID still showing, and so on... notice that I used the ROW() function to get 1,2,3...

  • Lastly, I used a simple VLOOKUP() to add in the Food, Amount, and Weight for the respective ID's.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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