Vba 代码工作得很好,除了需要设置值而不是公式

Vba 代码工作得很好,除了需要设置值而不是公式,vba,setvalue,Vba,Setvalue,好的,除了如何将表1中单元格的值而不是公式复制到表2之外,这非常有用?与日期传输为1900年1月0日一样,当日期需要为2011年5月5日时,需要使用PasteSpecial方法,将XLPasteValue作为PasteType。比如: Private Sub CommandButton1_Click() Dim rCell As Range Dim i As Long Dim rNext As Range 'loop through the cells in column A of the so

好的,除了如何将表1中单元格的值而不是公式复制到表2之外,这非常有用?与日期传输为1900年1月0日一样,当日期需要为2011年5月5日时,需要使用PasteSpecial方法,将XLPasteValue作为PasteType。比如:

Private Sub CommandButton1_Click()
Dim rCell As Range
Dim i As Long
Dim rNext As Range
'loop through the cells in column A of the source sheet
For Each rCell In Sheet1.Range("A3:U25")
    'loop as many times as the value in column U of the source sheet
    For i = 1 To rCell.Offset(0, 22).Value
        'find the next empty cell to write to in the dest sheet
        Set rNext = Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(1, 0)
        'copy A and B from source to the dest sheet
        rCell.Resize(1, 22).Copy rNext.Resize(1, 1)

        Next i
    Next rCell
End Sub

您需要使用PasteSpecial方法,将xlPasteValues作为PasteType。比如:

Private Sub CommandButton1_Click()
Dim rCell As Range
Dim i As Long
Dim rNext As Range
'loop through the cells in column A of the source sheet
For Each rCell In Sheet1.Range("A3:U25")
    'loop as many times as the value in column U of the source sheet
    For i = 1 To rCell.Offset(0, 22).Value
        'find the next empty cell to write to in the dest sheet
        Set rNext = Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(1, 0)
        'copy A and B from source to the dest sheet
        rCell.Resize(1, 22).Copy rNext.Resize(1, 1)

        Next i
    Next rCell
End Sub
现在我在代码的下面部分得到了一个runtime-13类型不匹配。当出现错误时,单击“结束”,即可正常工作。不希望必须单击“结束”。 对于i=1到rCell.Offset(0,23).Value

现在我在代码的下面部分得到了一个runtime-13类型不匹配。当出现错误时,单击“结束”,即可正常工作。不希望必须单击“结束”。
对于i=1到rCell.Offset(0,23).Value,如果需要帮助,则需要将该代码格式化为可读格式。如果需要帮助,则需要将该代码格式化为可读格式。可能是因为您试图将较大范围粘贴到较小范围,请尝试更改读取
rNext.resize(1,1)的行.PasteSpecial(xlPasteValues)
rNext.Resize(1,23).PasteSpecial(xlPasteValues)
以便复制范围和粘贴范围大小相同。可能是因为您试图将较大范围粘贴到较小范围,请尝试更改读取
rNext.Resize(1,1).PasteSpecial(xlPasteValues)的行
将成为
rNext.Resize(1,23).PasteSpecial(xlPasteValues)
以便复制范围和粘贴范围大小相同。
Private Sub CommandButton1_Click()
Dim rCell As Range
Dim i As Long
Dim rNext As Range
'loop through the cells in column A of the source sheet
For Each rCell In Sheet4.Range("A3:U25")
    'loop as many times as the value in column U of the source sheet
    For i = 1 To rCell.Offset(0, 23).Value
        'find the next empty cell to write to in the dest sheet
        Set rNext = Sheet12.Cells(Sheet12.Rows.Count, 1).End(xlUp).Offset(1, 0)
        'copy A and B from source to the dest sheet
        rCell.Resize(1, 23).Copy
        rNext.Resize(1, 1).PasteSpecial (xlPasteValues)
    Next i
Next rCell
End Sub