How to repeat same number every n rows in the same column

%3CLINGO-SUB%20id%3D%22lingo-sub-2222437%22%20slang%3D%22en-US%22%3EHow%20to%20repeat%20same%20number%20every%20n%20rows%20in%20the%20same%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2222437%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20to%20repeat%20the%20same%20number%20every%20n%20rows%20within%20the%20same%20column%2C%20any%20thoughts%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20how%20can%20I%20do%20the%20same%20using%20a%20formula%20rather%20than%20a%20number%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20and%20I%20think%20%2C%20slightly%20more%20complicated%2C%20How%20can%20I%20add%20a%20formula%20in%20a%20cell%20depending%20of%20the%20colour%20of%20another%20cell%3F%20Trying%20to%20explain%20myself%20I%20meant%20IF%20the%20colour%20of%20an%20specific%20cell%20is%20%22X%22%20then%20use%20this%20formula%2C%20if%20is%20%22Y%22%20use%20this%20another%20formula%2C%20is%20that%20possible%3F%20%2Cand%20also%20repeat%20this%20pattern%20every%20n%20rows%20in%20the%20same%20column%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20not%20an%20expert%20in%20excel%20but%20I%20am%20trying%20to%20learn%20as%20much%20as%20possible%20to%20use%20for%20work%20as%20I%20am%20dealing%20with%20excel%20spreadsheets%20with%20a%20big%20amount%20of%20data%20and%20I%20think%20that%20would%20be%20useful%20rather%20than%20to%20add%20the%20numbers%20one%20per%20one%2C%20thanks%20in%20advance%20.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJulian%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2222437%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2223203%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20repeat%20same%20number%20every%20n%20rows%20in%20the%20same%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2223203%22%20slang%3D%22en-US%22%3EMaybe%20sharing%20the%20sheet%20and%2For%20more%20details%20on%20what%20you%20have%20and%20are%20trying%20to%20do%20would%20help.%3CBR%20%2F%3ETo%20repeat%20a%20number%20every%20n%20rows%20just%20do%20the%201st%20set%20of%20n%20rows%2C%20copy%2C%20then%20select%20the%20whole%20range%20of%20rows%20you%20want%20to%20fill%20that%20way%20and%20paste.%3CBR%20%2F%3EThe%20same%20method%20works%20whether%20the%20value%20in%20the%20cells%20are%20numbers%2C%20text%20or%20formulas%3CBR%20%2F%3Ebut%20the%20formula%20needs%20to%20be%20written%20accurately%20to%20indicate%20if%20any%20particular%20cell%20reference%20is%20ABSOLUTE%20or%20RELATIVE.%20By%20that%20I%20mean%20if%20a%20formula%20in%20cell%20A1%20is%20%3DB1%20%2B%201%20then%20you%20copy%20that%20down%20to%20A2%20then%20A2%20will%20have%20a%20formula%20%3DB2%20%2B%201%20because%20it%20will%20adjust%20B1%20down%20to%20B2%20accordingly.%20If%20instead%20you%20wanted%20it%20to%20stay%20with%20B1%20then%20add%20%24%20before%20each%20'fixed'%20component.%20So%20if%20A1%20had%20%3D%24B%241%20%2B%201%20then%20that%20reference%20to%20%24B%241%20will%20not%20change%20regardless%20of%20it%20being%20copied%20to%20a%20new%20cell%20location.%20Notice%20there%20is%20a%20%24%20before%20both%20the%20B%20and%20the%201%20but%20you%20can%20also%20choose%20to%20only%20'fix'%20one%20or%20the%20other%3A%20%24B1%20or%20B%241%20so%20%24B1%20will%20fix%20the%20B%20but%20not%20the%201%20so%20if%20you%20copy%20down%20rows%20the%201%20will%20change%20but%20if%20you%20copy%20to%20the%20a%20different%20column%20the%20B%20will%20not.%20and%20similarly%20with%20B%241%20if%20you%20copy%20to%20C1%20then%20the%20B%20will%20change%20to%20D%20but%20if%20you%20copy%20down%20rows%20the%201%20will%20stay%20fixed.%3CBR%20%2F%3EFinally%20as%20for%20detecting%20the%20color%20of%20the%20cell%2C%20that%20is%20only%20possible%20using%20VBA%20(macros).%20IF%20that%20color%20is%20being%20applied%20based%20on%20a%20conditional%20formatting%20rule%20then%20you%20can%20create%20a%20formula%20that%20replicates%20that%20rule%20to%20do%20the%20appropriate%20action.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2224457%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20repeat%20same%20number%20every%20n%20rows%20in%20the%20same%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2224457%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1002530%22%20target%3D%22_blank%22%3E%40castre1984%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYour%20question%20has%20two%20part%2C%20and%20this%20one%20is%20addressing%20first%20one%2C%20Repeat%20number%20in%20certain%20Rows.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Rajesh-S_1-1616220869844.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F265805i7D1AA483C4F33A2C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Rajesh-S_1-1616220869844.png%22%20alt%3D%22Rajesh-S_1-1616220869844.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3EHow%20it%20works%3A%3C%2FSTRONG%3E%3C%2FP%3E%3COL%3E%3CLI%3ECreate%20Index%20Column%20as%20shown%20in%20Col%20AC.%3C%2FLI%3E%3CLI%3EFormula%20in%20cell%20AD2%3A%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%3DIF(MOD(ROW()-1%2C5)%2C%22%22%2CSUM(OFFSET(AC2%2C-4%2C0%2C4%2C1)))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EWhere%205%20is%20Row%20interval%2C%20and%20-4%20%26amp%3B%204%20are%20value%20to%20repeat.%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSTRONG%3EN.B.%26nbsp%3B%3C%2FSTRONG%3E%3CEM%3ERemember%20Value%20to%20repeat%20must%20be%20smaller%20than%20Row%20interval.%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3ESolution%20for%20Part%20two%2C%20if%20the%20cell%20has%20color%26nbsp%3Bthen%20use%20a%20formula.%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Rajesh-S_0-1616222124413.png%22%20style%3D%22width%3A%20426px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F265807i3CC47D6556B45513%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Rajesh-S_0-1616222124413.png%22%20alt%3D%22Rajesh-S_0-1616222124413.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3EHow%20it%20works%3A%3C%2FSTRONG%3E%3C%2FP%3E%3COL%3E%3CLI%3ETo%20get%20VB%20editor%20either%20press%20ALT%2BF11%20or%20Right%20Click%20Sheet%20Tab%2C%20and%20from%20menu%20click%20View%20Code.%3C%2FLI%3E%3CLI%3ECopy%20%26amp%3B%20Paste%20this%20VBA%20code%20as%20Module.%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%3CSTRONG%3E%3CEM%3EFunction%20InteriorColor(CellColor%20As%20Range)%3C%2FEM%3E%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%3CEM%3EApplication.Volatile%3C%2FEM%3E%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%3CEM%3EInteriorColor%20%3D%20CellColor.Interior.ColorIndex%3C%2FEM%3E%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%3CEM%3EEnd%20Function%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%203.%20Return%20to%20the%20Sheet%2C%20and%20Save%20the%20WB%20as%20Macro%20Enabled%20*.xlsm.%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%204.%20Write%20this%20formula%20in%20cell%20AJ2%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DIF(AI2%26gt%3B0%2CAH2%2B1%2C%22No%20Color%22)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EN.B.%20%3C%2FSTRONG%3E%3CEM%3EFor%20neatness%20you%20may%20hide%20column%20AI.%3C%2FEM%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2224684%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20repeat%20same%20number%20every%20n%20rows%20in%20the%20same%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2224684%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F570951%22%20target%3D%22_blank%22%3E%40mtarler%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance%20for%20you%20answer%2C%20I%20am%20adding%20an%20excel%20doc%20to%20be%20more%20precise%2C%20you%20can%20find%20my%20questions%20in%20the%20question%20sheet.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi, 

 

I need to repeat the same number every n rows within the same column, any thoughts?

 

Also, how can I do the same using a formula rather than a number?

 

Also, and I think , slightly more complicated, How can I add a formula in a cell depending of the colour of another cell? Trying to explain myself I meant IF the colour of an specific cell is "X" then use this formula, if is "Y" use this another formula, is that possible? ,and also repeat this pattern every n rows in the same column?

 

I am not an expert in excel but I am trying to learn as much as possible to use for work as I am dealing with excel spreadsheets with a big amount of data and I think that would be useful rather than to add the numbers one per one, thanks in advance .

 

Julian 

7 Replies
Maybe sharing the sheet and/or more details on what you have and are trying to do would help.
To repeat a number every n rows just do the 1st set of n rows, copy, then select the whole range of rows you want to fill that way and paste.
The same method works whether the value in the cells are numbers, text or formulas
but the formula needs to be written accurately to indicate if any particular cell reference is ABSOLUTE or RELATIVE. By that I mean if a formula in cell A1 is =B1 + 1 then you copy that down to A2 then A2 will have a formula =B2 + 1 because it will adjust B1 down to B2 accordingly. If instead you wanted it to stay with B1 then add $ before each 'fixed' component. So if A1 had =$B$1 + 1 then that reference to $B$1 will not change regardless of it being copied to a new cell location. Notice there is a $ before both the B and the 1 but you can also choose to only 'fix' one or the other: $B1 or B$1 so $B1 will fix the B but not the 1 so if you copy down rows the 1 will change but if you copy to the a different column the B will not. and similarly with B$1 if you copy to C1 then the B will change to D but if you copy down rows the 1 will stay fixed.
Finally as for detecting the color of the cell, that is only possible using VBA (macros). IF that color is being applied based on a conditional formatting rule then you can create a formula that replicates that rule to do the appropriate action.

@castre1984 

Your question has two part, and this one is addressing first one, Repeat number in certain Rows.

 

Rajesh-S_1-1616220869844.png

How it works:

  1. Create Index Column as shown in Col AC.
  2. Formula in cell AD2:

 

=IF(MOD(ROW()-1,5),"",SUM(OFFSET(AC2,-4,0,4,1)))

 

 

  • Where 5 is Row interval, and -4 & 4 are value to repeat.

N.B. Remember Value to repeat must be smaller than Row interval.

 

Solution for Part two, if the cell has color then use a formula.

 

Rajesh-S_0-1616222124413.png

How it works:

  1. To get VB editor either press ALT+F11 or Right Click Sheet Tab, and from menu click View Code.
  2. Copy & Paste this VBA code as Module.

Function InteriorColor(CellColor As Range)
Application.Volatile
InteriorColor = CellColor.Interior.ColorIndex
End Function

 

    3. Return to the Sheet, and Save the WB as Macro Enabled *.xlsm.

    4. Write this formula in cell AJ2:

 

=IF(AI2>0,AH2+1,"No Color")

 

N.B. For neatness you may hide column AI.

@mtarler 

Thanks in advance for you answer, I am adding an excel doc to be more precise, you can find my questions in the question sheet.

Hi, thanks for the answer!, but i think my issue is more complex, I already attached a excel doc answering @mtarler, let me know if you cannot find the excel doc and I'll share a copy with you.

Ragards

Julian

@castre1984 

If without VBA

1) I'd create helper column (you may hide it) which fills down value in I15, other every 12 cell in column I could use reference on this helper column

2) To define an option I'd use not the cell property such as color, but some values, perhaps from drop-down list. Based on selected value you may do this or that calculations. To color the cell(s) you may use conditional formatting on the top.

@castre1984 hello, easiest is to use if function along with mod to make repeated pattern, then for colors use conditional formatting with formulas

attached sample, hope this helps

@chahine 

You shall insert the value in every 12th cell (5th in your case) without touching values in the cells in between. =$I$15 could work, but I'm not sure what are limitations.

Colors is another question, these are using of different formulas depends on cell color.