Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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
Excel 根据与定义名称相等的列中的值复制行_Excel_Vba - Fatal编程技术网

Excel 根据与定义名称相等的列中的值复制行

Excel 根据与定义名称相等的列中的值复制行,excel,vba,Excel,Vba,我试图创建一个宏,该宏将根据C列中的值复制整行,该值等于我定义的一个名称(它是一个日期),然后,它将值完全粘贴在同一个位置-类似于冻结函数 这里是我到目前为止所做的,但是代码在运行后根本没有响应(没有错误,实际上什么都没有)。我一直在研究类似的主题,下面是我发现的与我想要得到的相匹配的混合: Sub testIt() Dim r As Long, endRow As Long, pasteRowIndex As Long endRow = 1000 ' preferably change fo

我试图创建一个宏,该宏将根据C列中的值复制整行,该值等于我定义的一个名称(它是一个日期),然后,它将值完全粘贴在同一个位置-类似于冻结函数

这里是我到目前为止所做的,但是代码在运行后根本没有响应(没有错误,实际上什么都没有)。我一直在研究类似的主题,下面是我发现的与我想要得到的相匹配的混合:

Sub testIt()
Dim r As Long, endRow As Long, pasteRowIndex As Long

endRow = 1000 ' preferably change for a function that will retrieve the last used row number via a function

For r = 7 To endRow 'Loop through sheet1 and search for your criteria

    If Cells(r, Columns("C").Column).Value = ThisWorkbook.Names("MyDate").Value Then Rows(r).Select

    For Each cell In Selection
    cell.Value = cell.Value
    Next cell
    End If
Next r
End Sub

我将非常感谢一些提示。

当我测试这个时,我发现名称的值返回它的地址,而不是它的实际值,所以请使用范围。此外,不需要选择并循环每个单元格(尽管我怀疑您是否需要对整行进行操作)


FWIW(与您问题中提到的问题无关)
Cells(r,Columns(“C”)。Column)
只需说
Cells(r,C”)
就可以更轻松地编写,它工作得非常好!一如所料:)非常感谢您的快速回复!
Sub testIt()

Dim r As Long, endRow As Long, pasteRowIndex As Long

endRow = 1000 ' preferably change for a function that will retrieve the last used row number via a function

For r = 7 To endRow 'Loop through sheet1 and search for your criteria
    If Cells(r, 3).Value = Range("MyDate").Value Then
        Rows(r).Value = Rows(r).Value
    End If
Next r
'Alternatively you could use ThisWorkbook.Names("MyDate").Referstorange.Value
End Sub