[英]Update Column Range with the cell value
I have an input sheet called "Testfall-Input-Vorschlag where we have to choose a value from a dropdown in the cells of the first row from the 7th (J)column and when a value gets chosen for example "ARB13" I want to fill out the column where it is selected. The filling of the column is with random values. There is a Sheet called "Admin" which has values stored in the cells of columns from A:ZZ. Now I in the "Testfall-Input-Vorschlag" sheet I want to fill out the cells of the column sequentially. Which means for example for cell(11,7) i want to generate a random value from column A in "Admin" for cell (12,7) the value has to be from Column B in "Admin" for cell (13,7) the value is from column C in "Admin and so on. 我有一个名为“Testfall-Input-Vorschlag”的输入表,我们必须从第7(J)列的第一行单元格的下拉列表中选择一个值,当选择一个值时,例如“ARB13”我想要填写选中它的列。列的填充是随机值。有一个名为“Admin”的Sheet,其值存储在A:ZZ列的单元格中。现在我在“Testfall-Input- Vorschlag“表格我希望按顺序填写列的单元格。这意味着例如对于单元格(11,7)我想从”Admin“中的列A生成一个随机值,用于单元格(12,7),该值具有对于单元格(13,7)的“Admin”中的B列,该值来自“Admin”中的C列,依此类推。 So I have been trying and I've come up with this code
所以我一直在尝试,我已经提出了这个代码
Sub ARB13()
Dim col As Integer
For i = 11 To 382
For j = 7 To 1000
If Sheets("Testfall-Input_Vorschlag").Cells(1, j) = "ARB13" Then
col = 0
col = col + 1
LB = 2
UB = Sheets("Admin").Range("col" & Rows.Count).End(xlUp).Row
Cells(i, j).Select
ActiveCell.FormulaR1C1 = Sheets("Admin").Range("Y" & Int((UB - LB + 1) * Rnd + LB))
End If
Next j
Next i
End Sub
How can I update the col value for every i. 如何更新每个i的col值。 Which means for every i I need col value to be increased by 1. Where am I going wrong?
这意味着每一个我需要的col值增加1.我哪里出错了?
Define col
before you start your first loop, and don't put col = col + 1
in the For j = 7 to 1000
loop. 在开始第一个循环之前定义
col
,并且不要将col = col + 1
放在For j = 7 to 1000
循环中。 Otherwise col
will increment for every j
instead of every i
. 否则
col
将为每个j
而不是每个i
递增。 Something like this: 像这样的东西:
Sub ARB13()
Dim col as Long
Dim i as Long
Dim j as Long
col = 0
For i = 11 To 382
For j = 7 to 1000
LB = 2
UB = Sheets("Admin").Cells(Rows.count, col).End(xlUp).row
Cells(i, j).Select
ActiveCell.FormulaR1C1 = Sheets("Admin").Range("Y" & Int((UB - LB + 1) * Rnd + LB))
Next j
col = col +1
Next i
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.