Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 做一个不带“的循环”;“预定义”;单元格(即仅“B”而不是“b5”)_Vba_Loops_Excel - Fatal编程技术网

Vba 做一个不带“的循环”;“预定义”;单元格(即仅“B”而不是“b5”)

Vba 做一个不带“的循环”;“预定义”;单元格(即仅“B”而不是“b5”),vba,loops,excel,Vba,Loops,Excel,我的问题是:我试图在一组特定的数据上运行一个循环,每次更新的数据量都会发生变化。如果分数>0,则它将剪切/粘贴A、B和C列中的特定行,并将其粘贴到图纸数据中下一个可用的自由行中。 这就是我到目前为止所拥有的: Sub whatever() Dim score As Integer, sStart As Integer, sTeller As Integer, lcount As Integer, result As String sStart = Sheets("Packed"

我的问题是:我试图在一组特定的数据上运行一个循环,每次更新的数据量都会发生变化。如果分数>0,则它将剪切/粘贴A、B和C列中的特定行,并将其粘贴到图纸数据中下一个可用的自由行中。 这就是我到目前为止所拥有的:

Sub whatever()
    Dim score As Integer, sStart As Integer, sTeller As Integer, lcount As Integer, result As String

    sStart = Sheets("Packed").Range("F1").Value
    sTeller = Sheets("Packed").Range("E1").Value
    lcount = sStart
    score = Range("B& lcount").Value

    Do While lcount < sTeller
        Sheets("Packed").Select
        If score > 0 Then _ 
            Range("A&lcount:C&lcount").Select
        Selection.Cut
        Sheets("data").Select
        Range("A5").Select
        Selection.End(xlDown).Select
        Selection.Offset(1, 0).Select
        ActiveSheet.Paste
        lcount = lcount + 1
    Loop
End Sub
Sub-where()
Dim分数为整数,sStart为整数,sTeller为整数,lcount为整数,结果为字符串
sStart=板材(“包装”).范围(“F1”).值
sTeller=板材(“包装”).范围(“E1”).值
lcount=ssStart
分数=范围(“B&L计数”)。值
当lcount0,则
范围(“A&L计数:C&L计数”)。选择
选择,剪
工作表(“数据”)。选择
范围(“A5”)。选择
选择。结束(xlDown)。选择
选择。偏移量(1,0)。选择
活动表。粘贴
lcount=lcount+1
环
端接头
我希望VBA将“lcount”添加到rowlabel中,然后针对B中有数据的每一行循环它。
提前感谢:)

在此代码中连接带引号的字符串时,您包含了太多的“片段”:

If score > 0 Then _ 
    Range("A&lcount:C&lcount").Select
以下是一些建议:

If score > 0 Then _ 
    Range("A" & lcount & ":C" & lcount).Select

If score > 0 Then _ 
    Cells(lcount, "A").Resize(1, 3).Select

您可能还需要查看中详细介绍的方法。

循环在您的案例中不是必需的,请参阅下面更新的代码

Sub whatever()
    Dim score&, sStart&, sTeller&, lcount&
    lcount = Sheets("data").Cells(Rows.Count, "A").End(xlUp).Row + 1
    With Sheets("Packed")
        sStart = .Range("F1").Value
        sTeller = .Range("E1").Value
        score = .Range("B" & sStart).Value
    End With
    If score > 0 Then
        Sheets("Packed").Range("A" & sStart & ":C" & sTeller - 1).Cut
        Sheets("data").Activate: Range("A" & lcount).Insert xlDown
    End If
End Sub
尝试
范围(“B”&l计数)
。如果
lcount
=5,则将计算为
范围(“B5”)
。。。或
单元格(lcount,“B”)
单元格(lcount,2)
。见和。