我正在尝试(使用VB)将7个值从1个位置复制到另一个位置。 (从F115复制到F134。) (F115是数字来源; F134是数字的目的地) 如果F134中有数据(任何数据),我想将行前进1,然后打印/复制。我不想覆盖任何数据行。 因此,如果第一行中有数据(F134),那么我想将行计数移动/提前1,然后将值复制到行F135中 - 依此类推。可能有500到100行数字,我需要能够查看所有这些数据。 到目前为止,这是我的代码:有些可行,但它不会提前计算行数并继续打印到Cell F134。 (哦,是的,F124只是一组空单元格。)
好的,这是我的代码;
Sub dbtest4()
Dim RowCounter As Integer
rowCounter = 1
Do Until rowCounter = rowCounter +1
'trying to advance the row counter by 1 such that if there is data in F134, the line count will advance and the new data will print into the NEXT line. (which would be F135)
'the following code probably is unnecessary, but I'm trying anything...
'actually the following code works ok: Range("F134").Resize(1,7).Value = Range("F115").Resize(1,7).Value, but that's about it.
If Range ("F134") = 0 then
Range("F134").Resize(1,7).Value = Range("F115").Resize(1,7).Value
'trying to print data cells from F124 if there is no data in F134
Else
Range("F134"),Resize(1,7).Value = Range("F124).Resize(1,7).Value
'trying to print the zeros or blank numbers from F115 if F134 has data in it
End if
Loop
Exit Do
End Sub
感谢能够提供帮助的任何人。
答案 0 :(得分:0)
现在,Do While循环的退出条件是rowCounter必须递增1。我不明白为什么这会失败的原因,这就是为什么它只发生一次。这是一些伪代码:
Do Until copiedVals = 7 'Or whatever exit value you want
If row.Value.Exists() then
'There is a value in this row, so increment the row count
rowCounter = rowCounter + 1
Else
'This row is empty and you can do your thing
'rowCounter will have the current row value
copiedVals = copiedVals + 1
End If
End Loop