How to fill cells in Excel in particular sequence?

Click For Summary

Discussion Overview

The discussion revolves around how to fill a row in Excel with a specific sequence of values (four cells with value 1 followed by four cells with value 0) without manually copying and pasting. Participants explore various methods, including formulas and macros, to achieve this efficiently.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant proposes a formula to fill cells: =INT(MOD(MOD((COLUMN(A4)+3)/4,4),2), suggesting it can be copied across the row.
  • Another participant expresses that the proposed formula does not work as intended and seeks clarification on how to achieve the desired result without copying and dragging.
  • A participant suggests using a macro to automate the copying of blocks of cells, providing a sample code for this purpose.
  • There is a discussion about the familiarity with macros and how to implement them in Excel, with one participant asking for guidance on where to place the macro.
  • Clarifications are made regarding the workings of the proposed formula, including how the column function is utilized and the significance of the values 1 and 0 in the context of the formula.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the effectiveness of the proposed formula, as some find it does not meet their needs while others believe it should work. The discussion remains unresolved regarding the best method to achieve the desired cell filling.

Contextual Notes

Participants express uncertainty about the limitations of the formula and the macro approach, indicating a need for further clarification on how to implement these solutions effectively.

Adel Makram
Messages
632
Reaction score
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
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 ?​
 
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: 568
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
 
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?
 
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
 

Similar threads

  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 14 ·
Replies
14
Views
6K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K