Incrementing each row in excel that contains a number - excel

I was sent an excel document in the following format:
A | B |
1 | abc |
| def |
2 | abc |
| def |
| ghi |
3 | abc |
| def |
So basically I have the first column which contains ordered numbers every couple of rows. I want to insert a row e.g. between 2 and 3, so that the new row will be numbered 3, and the rows below it are updated accordingly i.e. 3 becomes 4, 4 becomes 5 and so on.
I don't really use excel, but I am curious if there is there an easy way of doing this?

In A1, enter the following formula:
=IF(MOD(ROW(A1),2)=1,(ROW(A1)+1)/2,"")
And copy that formula down to the bottom of the range. Each time you insert a new row, you will need to manually copy the formula to the inserted row's first cell.

Is there a pattern in the b column, to distinguish if you need to jump to the next number?
if so use:
in cel A2 and further:
=IF(B2 = "abc",A1+1,A1)
With conditional formating, hide the repeating numbers: =A2=A1

Related

I have a list of keywords and want to count the number of match keywords in each cells text from EXCEL File

I have 2 sheet in a excel file. one is a Dictionary sheet and 2nd is a sheet containing a column of text. I want to match the dictionary keywords columns one by one and then the number of match keywords counts in each cell of the text column.
I have tried these formulas:
=(LEN(B2)-LEN(SUBSTITUTE(B2,Sheet1!A:A,"")))/LEN(Sheet1!A:A)
in this B2 is the first (start) cell of the text column and Sheet1!A:A is the dictionary column of other sheet.
but by this i get zero as a result
=(LEN(B2)-LEN(SUBSTITUTE(B2,Sheet1!A:A,"")))/LEN(Sheet1!A:A)
The result will be like this:
Text number_of_keyword_match | number_of_keyword_match using DIC col 2 | ........
using DIC col 1
1 any Text or sentence/sentences e.g match "3"
2 7
3 0
4 15
5 .................................................
7 .....................................................
.......................................................
..................................continue up to 2815 rows....
Assuming your text input looks like this:
| A |
-+----------------------+
1|apple apple beat beat |
2|apple beat beat carrot|
3|carrot apple apple |
and your dictionary looks like this:
| A | B |
-+-------+-------+
1|apple |beat |
2|beat |carrot |
3| | |
This formula will give you the count per word per cell of text
=(LEN(text!A1)-LEN(SUBSTITUTE(text!A1,dictionary!A1,"")))/LEN(dictionary!A1)
(In this example 2)
If I understand correctly, your expected output would be extra columns in the text sheet where each cell contains the sum of counts of each word in the corresponding column in dictionary, right? For example:
| A | B | C |
-+----------------------+---+---+
1|apple apple beat beat | 4 | 2 |
2|apple beat beat carrot| 3 | 3 |
3|carrot apple apple | 2 | 1 |
You can use array formulas to do this, starting with this one in cell B1:
=SUM(IFERROR((LEN(text!$A1)-LEN(SUBSTITUTE(text!$A1;dictionary!A:A;"")))/LEN(dictionary!A:A);0))
But instead of pressing Enter after pasting it in, press Ctrl+Shift+Enter to run it as an array formula. Then drag this formula down and to the right to get all the counts you want.
I would consider countif(), as an example:
=COUNTIF(Sheet2!A1:A10,Sheet1!A1)
which assumes your list starts in cell A1 on sheet1 and your text in cell a1 on sheet2.
To drag the formula as I showed it, without the data range moving you need :
=COUNTIF(Sheet2!A$1:A$10,Sheet1!A1)
if you put $ before the letters, then the columns don't move.

excel - transpose (rows to columns) with extra dimension?

is it possible to transpose rows to columns with extra dimensions??
imagine table:
dimension | data 1 | data 2 | data 2
---------------------------------------
test | a | b |
dummy | c | e | x
user | a | d |
john doe | v | |
I need to get this:
dimension | data
-------------------
test | a
test | b
dummy | c
dummy | e
dummy | x
user | a
user | d
john doe | v
Is there any built-in function? Or do I need to use macro?
Obviously this is more straightforward with VBA, though it can be done using worksheet formulas along, viz:
Assuming your source table is in A1:D5 (with headers in row 1), enter this array formula** in F2:
=IF(ROWS($1:1)>COUNTIF(B$2:D$5,"<>"),"",INDEX(A$2:A$5,MATCH(ROWS($1:1),1+MMULT(0+(ROW(B$2:D$5)>TRANSPOSE(ROW(B$2:D$5))),MMULT(0+(B$2:D$5<>""),TRANSPOSE(COLUMN(B$2:D$5)^0))))))
Copy down until you get blanks for the results.
Then enter this formula in G2:
=IF(F2="","",INDEX(INDEX(B$2:D$5,MATCH(F2,A$2:A$5,0),),COUNTIF(F$2:F2,F2)))
Copy down as required.
Note that this set-up assumes that it is not possible for a given dimension to have blank entries in between non-blank entries within the data columns, for example data1 and data3 are non-blank but data2 is blank. This is the case for the data you provided so seems like a fair assumption.
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

How can I conditionally VLOOKUP in Excel?

Suppose I have the table I need to VLOOKUP() through:
id | indicator | value
-----------------------
1 | a | abc
1 | b | def
1 | c | ghi
2 | a | bbc
2 | b | bef
3 | a | aef
There is a table where I need to attach only values with indicator equal to a:
id | value
----------
1 | abc
2 | bbc
3 | aef
Something like conditional VLOOKUP() is required. What is the elegant way to do it?
You can do multiple criteria INDEX-MATCH to achieve this:
=INDEX($C$1:$C$6,MATCH($E1&"a",$A$1:$A$6&$B$1:$B$6,0))
This is array formula and it works by hitting Ctrl+Shift+Enter.
Also, I assumed that your Lookup value is in cell E1, which is something you can change according to your needs.
Use an array formula:
I found this formula in the web a few years ago, cant remember where, but credit to them.
=VLOOKUP(CONCATENATE(D2,"a"), CHOOSE({1,2},A$1:A$10 & B$1:B$10, C$1:C$10 ),2,0)
For this example I used column D on the same sheet for the reference ID and column E for the result. Amend the references as required.
Due to this being an array formula, every time the formula is entered you will need to select the formula bar and hold CTRL and Shift and press enter on the keyboard.

Increment count in column based on value in column

I've 2 columns A and B. A contains names and B contains the count of those names till that record as shown below.
-----------------------------------
| A | B |
-----------------------------------
1 | Fruits | 1 |
2 | Flowers | 1 |
3 | Fruits | 2 |
So, want to have a formula for this. Expecting an array formula. Even if an array formula is not possible, a general formula
Attached a spreadsheet so that it can be explained better.
https://docs.google.com/spreadsheets/d/1wlWqdFwgv90s50iP-bXXBHciyualohj610qFiSatcmQ/edit#gid=1997586177
You do not need an array formula, and I would avoid them when possible. You can accomplish your task with
=COUNTIF(A$1:A1,A1)
Where A1 if the first value in the column of values you want to count. The $ allows you to anchor the top of your COUNTIF range while leaving the bottom dynamic.
In a google spreadsheet you may want to try:
=ArrayFormula(iferror(SORT(ROW(A1:A),SORT(ROW(A1:A),A1:A,1),1)-MATCH(A1:A,SORT(A1:A),0)-ROW()+2))
Example sheet

Google spreadsheet relative row numbering + skip empty cell

Using Google spreadsheet, I need a column to show relative row numbering, so that:
Spreadsheet rows can be moved around, and numbering stays relative (meaning that if I move row number 12 between rows 4 and 5, this row becomes number 5, previous 5 becomes 6, etc.)
Using a condition based upon a cell value in a given row, the row numbering cell may be empty (or not); if empty, that row number is being skipped, and numbering takes back up in the next row where the condition is unmatched.
Here is an example:
| Row nbr | B col. | [Explanation] |
|---------|:-------:|-------------------------------------|
| R01 | Value 1 | |
| R02 | Value 1 | |
| R03 | Value 2 | |
| | Value 3 | Col. B value = 3 => Col. A is empty |
| R04 | Value 2 | Numbering takes up |
| R05 | Value 1 | |
| | Value 3 | Col. B value = 3 => Col. A is empty |
| R06 | Value 2 | Numbering takes up |
| ETC. | | |
Here, the condition (to skip numbering) would be "IF corresponding B cell = Value 3" (then skip numbering)
Right now, I'm using a formula that matches requirement #1 above:
=ROW(INDIRECT("A"&ROW()&":A"))-9
(The trailing "-9" is just an offset so numbering can start at 01 from row 10).
So basically, I need to adapt (or change) this code so that besides relative numbering, for row N, if corresponding B column cell value = XYZ, then A column cell is empty (vs. numbered): that row is being skipped, and numbering takes back up from N on the next row where the B cell value ≠ XYZ.
Here's a Google spreadsheet example.
Many TIA's.
I strongly recommend not to use ROW() with explicitly specified offset in formula because should you delete/add rows above your table, your will have to adjust formulas in all cells. Here's my solution (column A:A is row numbers, B:B - values, start adding formula in cell A10):
=IF($B10="Value 3","",ROWS($B$10:$B10)-COUNTIF($B$10:$B10,"Value 3"))
Or if you insist on relative rows (change 10 to your offset from top):
=IF(INDIRECT("B"&ROW())="Value 3","",ROWS(INDIRECT("B"&10&":B"&ROW()))-COUNTIF(INDIRECT("B"&10&":B"&ROW()),"Value 3"))

Resources