循环并select下一个单元格excelmacros

你好希望一切都很好:)有困难搞清楚如何循环和select下一个单元格,当一个单元格在范围h3:z3是空的,将停止:)

它在做的是从h3中select数值粘贴在b3中运行另一个macros,它给出了e3中的订单号,然后复制并粘贴到h4中,然后它将转到I3中的下一个单元格粘贴b3从e3中复制结果并粘贴在I4中,并执行相同的操作

谢谢

For Each cell In Range("H3:Z3") If IsEmpty(cell.Value) Then Exit For 'select ammount and place in lookup Range("H3").Select Selection.Copy Range("B3").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False ' fill in order numbers bulkON_Click 'select order and past under postcode Range("E3").Select Application.CutCopyMode = False Application.CutCopyMode = False Selection.Copy Range("H4").Select ActiveSheet.Paste Loop 

有很多,我可能会改变这个代码。 这应该让你开始。

对于初学者来说,一个For循环需要一个Next语句,而不是一个Loop (用于Do块),而且,你应该避免不惜一切代价地复制/粘贴,直接把值写入目标单元格。

我假设单元格“B3”和“E3”是恒定的,并且您正在遍历H3:Z3中的单元格,并计算一些值以放入H4:Z4中的对应单元格。

 For Each Cell In Range("H3:Z3") If Cell.Value = vbNullString Then Exit For 'select ammount and place in lookup Range("B3").Value = Cell.Value '<< no need to "copy & paste", just write the value directly ' fill in order numbers bulkON_Click 'insert the value under postcode ' this OFFSET refers to the cell 1 row below the "Cell" Cell.Offset(1, 0).Value = Range("E3").Value Next