我已经很长时间没有使用VBA了,我正在尝试创建一个用于制作时序图的用户界面类型的东西。下面您会看到我有一个进程列表以及每个进程需要多长时间。用户将在右侧的单元格中输入从1开始的数字 我要编写的程序需要执行以下操作:
任何有数字的行都会复制B和F列中的信息,然后将其粘贴到第39行+发现的任何数字中。这将在图表中创建一个顺序正确的列表,如下所示。 我试图编写一个程序,该程序循环遍历该数字输入区域中每一列的每一行,但是我的VBA达不到标准,并且出现了问题。任何帮助将不胜感激。下面是到目前为止我没有成功使用的代码 经过编辑以反映删除了“ range(” 答案 0 :(得分:2) 要获取数字,将其放在A39中并抄下来: 要获取操作,请将其放在B29中并复制下来: 要获取时间,请将其放在F39中并抄下来: 因此,数据如下: 使用这些公式,我们得到: 如果您真的想要vba,请忘记使用offset,而只需参考以下列:# bad - uses DateTime for current time
DateTime.now
# good - uses Time for current time
Time.now
# bad - uses DateTime for modern date
DateTime.iso8601('2016-06-29')
# good - uses Date for modern date
Date.iso8601('2016-06-29')
# good - uses DateTime with start argument for historical date
DateTime.iso8601('1751-04-23', Date::ENGLAND)
1 个答案:
=IFERROR(SMALL($M$4:$AG$33,ROW(A1)),"")
=IF(A39<>"",INDEX(B:B,AGGREGATE(15,7,ROW($M$4:$AG$33)/($M$4:$AG$33=A39),COUNTIF($A$39:A39,A39))),"")
=IF(A39<>"",INDEX(F:F,MATCH(B39,$B:$B,0)),"")
Sub TimingChart()
With ThisWorkbook.Worksheets("Sheet1")
Dim rng As Range
Set rng = .Range("M4:AG33")
'loop columns
Dim col As Range
For Each col In rng.Columns
'loop rows of that column
Dim cel As Range
For Each cel In col.Cells
'skip cells with nothing in them
If cel.Value = "" Then
'any cell with a number copy the data in row B and row F and
'paste in the chart below the entry field starting in row 40
'the data should copy into row 39 + x putting the operations in order
Else
'x is the variable for row adjustment to determine what cell to paste into
Dim x As Long
x = cel.Value
.Cells(cel.Row, 2).Copy .Cells(39 + x, 2)
.Cells(cel.Row, 6).Copy .Cells(39 + x, 6)
cel.Copy .Cells(39 + x, 1)
End If
Next cel
Next col
End With
End Sub