简体   繁体   English

剪切范围并将其粘贴到单元格上的代码,例如excel(VBA)

[英]Code to Cut a range and paste it on a cell like if it was excel (VBA)

I'm trying to use this code to cut and paste some data: 我正在尝试使用以下代码来剪切和粘贴一些数据:

For c = p To 12
    If Sheets("Hoja2").Cells(4, 3 + c + yy).Value <> "Total general" Then
        c2 = p - 1
        dif = Sheets("Hoja2").Cells(4, 3 + c + yy).Value - Sheets("Hoja2").Cells(4, 3 + c2 + yy).Value
        If Sheets("Hoja2").Cells(4, 3 + c + yy).Value - Sheets("Hoja2").Cells(4, 3 + c2 + yy).Value <> 1 Then
            Sheets("Tabla Final REV").Range(Cells(5, (4 * (e * 3 + t) + 4 * (1 - t) + p - 1)), Cells(variablefinalfila, 15)).Cut Sheets("Tabla Final REV").Range(Cells(5, (4 * (e * 3 + t) + 4 * (1 - t) + p + dif - 1 - 1)), Cells(5, (4 * (e * 3 + t) + 4 * (1 - t) + p + dif - 1 - 1)))
        End If
    Else
        Exit For
    End If
Next c

But it doesn't paste anything. 但它不会粘贴任何内容。

In other words my code is just: 换句话说,我的代码就是:

For x = 1 to 12 
     if condition
      if othercondition
         Sheets("Mysheet").Range(cells(number,number2), cells(number3,number4)). Cut Sheets("Mysheet").Range(cells(anumber,anumber2),cells(anumber,anumber2))

What can I do to improve it?? 我可以做些什么来改善它?

Qualify those Cells may fix it: 确认那些Cells 可以修复它:

 With Sheets("Tabla Final REV")
    .Range(.Cells(5, (4 * (e * 3 + t) + 4 * (1 - t) + p - 1)), .Cells(variablefinalfila, 15)).Cut .Range(.Cells(5, (4 * (e * 3 + t) + 4 * (1 - t) + p + dif - 1 - 1)), .Cells(5, (4 * (e * 3 + t) + 4 * (1 - t) + p + dif - 1 - 1)))
 End With

Notice the dots in front of the .Cells 请注意.Cells前面的点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM