How to fill cells in Excel in particular sequence?

In summary, the conversation discusses a method for filling a row with a repeating pattern of 4 cells with value 1 followed by 4 cells with value 0. This can be achieved by using the formula =INT(MOD(MOD((COLUMN(A4)+3)/4,4),2)) and copying it to the right multiple times. Alternatively, a macro can be used to copy the pattern to the desired location.
  • #1
Adel Makram
635
15
Suppose I need to fill a row composed of 32 cells with a sequence of 4 cells with value 1 in a row followed by 4 cells with value 0 in a row and then again 4 cells of 1 and so on. How can I do this without copying those cells and repeating pasting them in their location?
 
Computer science news on Phys.org
  • #2
If you put the following in e.g. cell A4

=INT(MOD(MOD((COLUMN(A4)+3)/4,4),2))

You can copy that cell to the right ad libitum. But is that really what you want ?​
 
  • #3
BvU said:
If you put the following in e.g. cell A4

=INT(MOD(MOD((COLUMN(A4)+3)/4,4),2))

You can copy that cell to the right ad libitum. But is that really what you want ?​
I tried this but it does not work.
I attach a pic to illustrate my thought. I wish to copy the 4 cells (1010) highlighted in dark green to the right so as to fill the rest of the row highlighted in light green. I wish the result to be similar to the next row highlighted in dark green. I need to do this in a fast way no matter how long will be the row. I wish to copy a formula like you did but I don`t want to copy (1010) and drag it down to the line before pasting it.
 

Attachments

  • Snap 2016-12-20 at 16.16.18.png
    Snap 2016-12-20 at 16.16.18.png
    11.6 KB · Views: 503
  • #4
Adel Makram said:
I tried this but it does not work.
That is strange. It does exactly what you describe, so in that sense it should work.

It comes as no surprise to me that it does not do what you want (hence also my question in posst #2) :smile:

I wouldn't know of an easy way to copy blocks of varying length (in your case 4) to side by side locations a variable number of times without resorting to a macro:

Code:
Sub MyCopy()

Selection.Copy

ncopies = InputBox("How many copies", "Block copy")

For icopy = 1 To ncopies
    Selection.End(xlToRight).Select
    ActiveCell.Cells(1, 2).Select
    ActiveSheet.Paste
Next icopy

End Sub
 
  • #5
BvU said:
That is strange. It does exactly what you describe, so in that sense it should work.

It comes as no surprise to me that it does not do what you want (hence also my question in posst #2) :smile:

I wouldn't know of an easy way to copy blocks of varying length (in your case 4) to side by side locations a variable number of times without resorting to a macro:

Code:
Sub MyCopy()

Selection.Copy

ncopies = InputBox("How many copies", "Block copy")

For icopy = 1 To ncopies
    Selection.End(xlToRight).Select
    ActiveCell.Cells(1, 2).Select
    ActiveSheet.Paste
Next icopy

End Sub
Where do I put this macro? I am not familiar with it?
Sorry to know that no other easier way to accomplish that. I like the first formula you advised but in that formula where is 1 and 0 and why does column appear? Have you tried it?
 
  • #6
Developer tab | Macros

Under Options... you can associate it with e.g. CTRL+SHIFT+G

Adel Makram said:
I am not familiar with it?
Very useful feature of Excel.

Adel Makram said:
Have you tried it?
Of course I have. :oldgrumpy:

In post #2 column() returns the column number; add 3, divide by 4
so 1,2, ..., 12, 13, 14 ##\rightarrow## 1, 1.25, ... 3.75, 4, 4.25​
take modulo 4 so that ...12, 13, 14 ##\rightarrow## ... 3.75, 0, 0.25
take modulo 2 so that 1,2, ..., 12, 13, 14 ##\rightarrow## 1, 1.25, 1.5, 1.75, 0, 0.25 ... 1.75, 0, 0.25
take int so that 1,2, ..., 12, 13, 14 ##\rightarrow## 1, 1, 1, 1, 0, 0 ... 1, 0, 0
 

Related to How to fill cells in Excel in particular sequence?

1. How do I fill cells in a specific sequence in Excel?

To fill cells in a specific sequence in Excel, you can use the "Fill" feature. Select the cells you want to fill, then click and drag the small square in the bottom right corner of the selection to the desired cells. You can also use the "Fill Series" option under the "Fill" drop-down menu to fill cells with a specific sequence, such as numbers or dates.

2. How do I fill cells with a custom sequence in Excel?

To fill cells with a custom sequence in Excel, you can use the "Custom Lists" feature. Go to "File" > "Options" > "Advanced" and scroll down to the "General" section. Click on the "Edit Custom Lists" button and enter your custom sequence in the "List entries" box. Click "Add" and then "OK". Now you can use this custom sequence to fill cells by selecting the cells and using the "Fill" feature or the "Fill Series" option.

3. Can I fill cells in a non-linear sequence in Excel?

Yes, you can fill cells in a non-linear sequence in Excel by using the "Custom Lists" feature or by manually typing in the desired sequence in the cells. You can also use formulas or functions to generate a non-linear sequence in Excel.

4. How do I fill cells in a column with the same value in Excel?

To fill cells in a column with the same value in Excel, you can use the "Fill" feature. Type the value in the first cell of the column, then select the cell and click and drag the small square in the bottom right corner of the selection to the rest of the cells in the column.

5. How do I fill cells in a row with the same value in Excel?

To fill cells in a row with the same value in Excel, you can use the "Fill" feature. Type the value in the first cell of the row, then select the cell and click and drag the small square in the bottom right corner of the selection to the rest of the cells in the row.

Similar threads

  • Computing and Technology
Replies
14
Views
2K
  • Computing and Technology
Replies
8
Views
2K
  • Computing and Technology
Replies
14
Views
3K
  • Precalculus Mathematics Homework Help
Replies
4
Views
666
Replies
1
Views
664
  • Computing and Technology
Replies
6
Views
2K
  • Biology and Medical
Replies
2
Views
1K
  • Computing and Technology
Replies
5
Views
2K
  • Computing and Technology
Replies
8
Views
1K
  • Computing and Technology
Replies
4
Views
3K
Back
Top