繁体   English   中英

无法粘贴和清除单元格内容

[英]Unable to paste and clear contents of cell

这是我的代码:

For j = 3 To 37 Step 2
If PaddleBDateInstalledTextBox.Value = Cells(j, 8).Value Then
        Cells(j, 8).Copy
        Range("D42").PasteSpecial Paste:=xlPasteValues
        Range("D42").PasteSpecial Paste:=xlPasteFormats
        Range("D42").PasteSpecial Paste:=xlPasteAllUsingSourceTheme '<-- 
        cells background, etc.
        Range("D42").NumberFormat = "MM/DD/YY"
        Cells(j, 8).Clear
 End If
Next

我有一个格式为日期的单元格,我试图先复制它,然后将其粘贴到另一个单元格中,但是我的单元格中没有粘贴值,也没有原始单元格中的值。 并且内容没有清除。

我有另一个具有Today()格式的单元格,我想只将没有公式的值复制到另一个单元格中,但是我也失败了。

我要复制的最后一个单元格的公式为=($I$2-H2)+(G2-F2) ,我遇到了同样的问题。

这段代码对我有用:

If 1 = Cells(1, 1).Value Then 'Assuming in Cell(1, 1) is the value 1
    Cells(1, 1).Copy
    Range("B1").PasteSpecial Paste:=xlPasteValues
    Range("B1").PasteSpecial Paste:=xlPasteFormats
    Range("B1").PasteSpecial Paste:=xlPasteAllUsingSourceTheme

    Range("B1").NumberFormat = "MM/DD/YY"
    Cells(1, 1).Clear
End If

也许是Cells(j, 8).Value 。值是您的问题。 j有什么价值? 如果j是变量,则您的代码应该是正确的,但是如果您将J作为列名,则代码应为Range("J" & 8).ValueCells(8, "J").Value而不是Cells(j, 8).Value

暂无
暂无

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

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