循环粘贴公式,直到范围内的下一个单元格为空 [英] Loop paste formula until next cell in range is empty
本文介绍了循环粘贴公式,直到范围内的下一个单元格为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将公式旁边的公式粘贴到单元格范围旁边,但只能包含一个值,脚本必须循环才能使该范围中的下一个单元格为空。例如Sheet 1列 A
包含直到第12行的日期,然后我想在列中粘贴一个公式:D12
请问
I am trying to paste a formula next to range of cells, but only the one's that contains a value, the script must loop until the next cell in the range is empty. For instance Sheet 1 Column A
contains date until row 12, then I would like to paste a formula in column D2:D12
Regards
推荐答案
这样吗?
Option Explicit
Sub Sample()
Dim lastRow As Long, i As Long
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
lastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
With ws
For i = 1 To lastRow
If Len(Trim(.Range("A" & i).Value)) <> 0 Then _
.Range("D" & i).Formula = "YOUR FORMULA"
Next i
End With
End Sub
这篇关于循环粘贴公式,直到范围内的下一个单元格为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文