Sub asd()
Sheets("Price calculator other regions").Range("E6").Value = Sheets("Sheet1").Range("B5")
Sheets("Price calculator other regions").Range("E25").Value = Sheets("Sheet1").Range("C5")
Sheets("Sheet1").Range("D5").Value = Sheets("Price calculator other regions").Range("E32")
End Sub
我需要B5,C5和D5值向下移动一行(B6,C6,D6等)直到最后一行,但是“价格计算器其他区域”上的值需要保持固定。
预先感谢
答案 0 :(得分:1)
进行价值转移而不是复制/粘贴的荣誉!
要完成循环,您只需要用计数器变量(变量i
)将相关的行号细分即可。要实现该功能,请找到最后一行(由Sheet 1 Column B
确定),然后循环遍历您的行。
循环当前设置为从Sheet 1
的第二行开始。如果您需要从第5行开始,请将循环更改为For i = 5 to LR
Sub asd_v2()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1")
Dim ps As Worksheet: Set ps = ThisWorkbook.Sheets("Price calculator other regions")
Dim LR As Long, i As Long
LR = ws.Range("B" & ws.Rows.Count).End(xlUp).Row
For i = 2 To LR
ps.Range("E6").Value = ws.Range("B" & i).Value
ps.Range("E25").Value = ws.Range("C" & i).Value
ws.Range("D" & i).Value = ps.Range("E32").Value
Next i
End Sub
答案 1 :(得分:0)
Dim r as range
set r = Sheets("Sheet1").Range("B5")
do 'start loop
with Sheets("Price calculator other regions")
.Range("E6").Value = r
.Range("E25").Value = r.offset(0,1)
r.offset(0,2) = .Range("E32")
set r = r.offset(1,0)
loop until r.row > r.parent.usedrange.rows.count
end with