Repeating a Pattern when Copying or Filling Cells

by Allen Wyatt
(last updated March 3, 2018)

3

Todd is setting up a comic book inventory list and would like each cell in column A to contain the text "Batman (1940) 0" repeated 3 times, followed by "Batman (1940) 1" repeated three times, "Batman (1940) 2" repeated 3 times, all the way through "Batman (1940) 700" repeated 3 times. That is 2,103 individual lines, but Todd isn't sure how to go about repeating patterns like this when copying or filling cells.

There are actually a few ways you can approach a task such as this. One way is to simply create a single sequence and then copy and paste twice. Here's the general idea:

  1. Into cell A1 enter the following: Batman (1940) 0
  2. Select cell A1.
  3. Drag the fill handle down to cell A701. This should give you a complete sequence of "Batman (1940) 0" through "Batman (1940) 700", and the cells in the range should still be selected.
  4. Press Ctrl+C to copy the range to the Clipboard.
  5. Paste the range into cell A702 and then again to cell A1403.
  6. Sort Column A.

This whole process goes very quickly; I was done with it in about 45 seconds. There is a drawback, though: After sorting, you won't get the sequence of cells in numeric order based on the number at the end of the text. If you want to ensure that, you'll want to enter your first comic book (in cell A1) as "Batman (1940) 000". When you use three digits for the ending number, the sorting will come out just fine.

There's another approach you can use that relies on the fill handle, as well. Follow these general steps:

  1. Into cell A1 enter the following: Batman (1940) 0
  2. Into cell A4 enter the following: Batman (1940) 1
  3. Select cells A1:A6. (This is very important.)
  4. Drag the fill handle down to cell A2103. This should give you a complete sequence of "Batman (1940) 0" through "Batman (1940) 700" with two empty cells after each item in the sequence, and the cells in the range should still be selected.
  5. Press F5. Excel displays the Go To dialog box.
  6. Click the Special button. Excel displays the Go To Special dialog box. (See Figure 1.)
  7. Figure 1. The Go To Special dialog box.

  8. Make sure the Blanks radio button is selected.
  9. Click on the OK button. Excel modifies the selection so that only the blank cells in the range are selected.
  10. In the Formula bar, type this formula: =A1
  11. Press Ctrl+Enter. This copies the formula to all the blank cells.
  12. Select cells A1:A2103.
  13. Press Ctrl+C to copy the range to the Clipboard.
  14. Use Paste Special to paste values. This converts the formulas back into values.

A third approach—one which I find very quick to accomplish—is to use a formula from the get-go:

  1. Into cell A1 enter the following formula: ="Batman (1940) "&INT((ROW()-1)/3)
  2. Select cells A1:A2103.
  3. Press Ctrl+D. The formula in cell A1 is copied to the rest of the selected range.
  4. Press Ctrl+C to copy the range to the Clipboard.
  5. Use Paste Special to paste values. (This converts the formulas back into values.)

If you need to create sequences such as this quite often, then you'll appreciate a macro-based approach. The following is simple, placing the desired text sequence into column A:

Sub ComicSequence()
    Dim sTemp As String
    Dim J As Integer
    Dim K As Integer

    sTemp = "Batman (1940) "
    For J = 0 To 700
        For K = 1 To 3
            Cells(J * 3 + K, 1).Value = sTemp & J
        Next K
    Next J
End Sub

To use a different preface to your cell values, all you need to do is to change the value you assign to the sTemp string.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9410) applies to Microsoft Excel 2007, 2010, 2013, and 2016.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Defining Styles

Styles are a powerful component of Word. You use them to determine the way that your text should appear. This tip ...

Discover More

Moving and Copying Cells

At the very heart of editing is the ability to move and copy cells in a worksheet. Understanding the differences between ...

Discover More

Where Is that Name?

Want to easily see the location of named ranges in your worksheet? It's easy; all you need to do is use the familiar Zoom ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Ensuring Standard Units During Data Entry

Need to make sure that information entered in a worksheet is always in a given unit of measurement? It's not as easy of a ...

Discover More

Extracting Numbers within a Range

If you have a large number of values in a column, you may want to move the values that meet specific criteria to another ...

Discover More

Deleting Everything Up to a Character Sequence

Sometimes you have too much information in a cell and you need to "pare down" what is there to get to the info you really ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is three more than 8?

2018-03-05 04:01:51

Thomas Papavasileiou

For my taste, in cases of sequences with a given number of characters (in this case we want tree digits), I would prefer ...001, ...002 to ...700.

This can be done by replacing:

Cells(J * 3 + K, 1).Value = sTemp & J
by
Cells(J * 3 + K, 1).Value = sTemp & Format(J, "000")


2018-03-04 10:52:40

Dave Bonin

Another approach would be to apply a custom number format such as:
"Batman (1940) "0;@

This will visually appear as requested, even when using a filter.

To go a little fancier, you could use:
"Batman (1940) "??0;@

This would make all of the digits line up.


2018-03-03 05:32:26

Harold Druss

Another way:
Sub RepeatBatman()
Dim strBatman As String
Dim i, j
i = 1
j = 0
strBatman = "Batman (1940) "
For i = 1 To 2103
Range("A" & i).Value = strBatman & j
If i Mod 3 = 0 Then j = j + 1
Next
End Sub


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.