我正在尝试自动填充以下行;
Row A1
Row A1
Row A2
Row A2
...
Row A12
Row A12
Row B1
Row B1
Row B2
Row B2
....
从A-P到1-12
如何快速自动填充此内容? 当前,向下拖动只会重复模式,而不会提升模式。
谢谢。
通常,在编程中,我会循环A-P并在其中嵌套1-12循环。但是,在excel中我不太确定。
答案 0 :(得分:3)
在一些数学运算中使用INDEX:
=INDEX($A$1:$P$12,MOD(ROW(1:1)-1,12)+1,INT((ROW(1:1)-1)/12)+1)
编辑,我误会了:
=CHAR(INT((ROW(1:1)-1)/12)+65)&MOD(ROW(1:1)-1,12)+1
当您向下拖动时,将用您的图案填充该列。
答案 1 :(得分:1)
如果您不反对在B中拥有可以自动填充的帮助程序列,则可以从A1
开始一路复制下来,然后复制并仅粘贴值。确保自动填充从0开始到所需的任意数量的单元格
=SUBSTITUTE(ADDRESS(1,CEILING((B1+0.01)/12,1),4),"1","") & MOD(B1,12)+1
编辑
抱歉,延迟,但是我花了一些时间在VBA中重写它,因此不再需要帮助列。
Sub Filler()
Dim i As Long
For i = 0 To 191
With ThisWorkbook.Worksheets(1)
.Cells(i + 1, 1) = Split(.Cells(1, Int((i + 0.01) / 12) + 1).Address, "$")(1) & i Mod 12 + 1
End With
Next i
End Sub
答案 2 :(得分:1)
Sub DAdwadw()
Dim i As Integer
Dim arr(0 To 16) As String
Dim count As Integer
arr(1) = "A"
arr(2) = "B"
arr(3) = "C"
arr(4) = "D"
arr(5) = "E"
arr(6) = "F"
arr(7) = "G"
arr(8) = "H"
arr(9) = "I"
arr(10) = "J"
arr(11) = "K"
arr(12) = "L"
arr(13) = "M"
arr(14) = "N"
arr(15) = "O"
arr(16) = "P"
arr(17) = "Q"
arr(18) = "R"
arr(19) = "S"
arr(20) = "T"
arr(21) = "U"
arr(22) = "V"
arr(23) = "W"
arr(24) = "X"
arr(25) = "Y"
arr(26) = "Z"
count = 1
For i = 1 To 8
Dim letter As String
For p = 1 To 58
letter = arr(i) & p
Cells(count, 1).Value = letter
Cells(count + 1, 1).Value = letter
count = count + 2
Next p
Next i
End Sub
这就是我最终这样做的方式。
答案 3 :(得分:0)
我认为您正在寻找类似的东西:
Option Explicit
Public Sub TestGeneratePattern()
GeneratePattern Rows:=12, Columns:=16
End Sub
Public Sub GeneratePattern(Rows As Long, Columns As Long)
Dim strRow As String
Dim strCol As String
Dim iRow As Long
For iRow = 1 To Rows * Columns
strRow = iRow - ((iRow - 1) \ Rows) * Rows 'count rows from 1 to 12
strCol = Cells(1, ((iRow - 1) \ Rows) + 1).Address(True, False) 'increase column every 12 rows
strCol = Left(strCol, InStr(1, strCol, "$") - 1) 'get column letter
Cells(iRow * 2 - 1, "A").Resize(RowSize:=2).Value = strCol & strRow 'write value in 2 cells at once
Next iRow
End Sub