使用下面的代码,我正在尝试执行以下操作:
我无法让循环正常工作,建议?谢谢!
编辑:我可以获得前2个值,然后循环无限期地运行而没有找到任何其他值。
Dim strOutputFile As Variant
Dim wbkOut As Workbook
Dim tenln As Range
Dim tenlnPaste As Range
Dim hasRun As Boolean
Dim wbkVer As Workbook
If strOutputFile(u) Like "*Lines.csv" Then
With wbkOut.Worksheets(1)
Set tenln = wbkOut.Worksheets(1).Cells(Rows.Count, 2).End(xlUp)
Set tenlnPaste = wbkVer.Worksheets("TLines").Range("A" & .Rows.Count).End(xlUp).Offset(1).Resize(tenln.Rows.Count, 1)
tenlnPaste.Value = tenln.Value
hasRun = True
Do
If hasRun = True Then
With wbkOut.Worksheets(1)
tenlnPaste.Offset(1, 0).Value = tenln.Offset(-1, 0).End(xlUp).Value
End With
End If
Loop Until tenln.value = ""
End With
End If
答案 0 :(得分:0)
你所写的do循环的问题在于你没有修改tenln
所以你在开头设置的任何值都将保持不变,而tenln = ""
将始终为false
如果我正确阅读了tenln
一个范围对象,那么你可以使用for循环。
For each c in tenln.cells
'your code here
If c.value = "" then exit for
Next