VBA: Why isn't variable working in named range?

后端 未结 3 1516
遥遥无期
遥遥无期 2021-01-20 19:14

This is part of a larger code, but this snippet isn\'t working. I\'m trying to just set two cells equal to each other, but it\'s not working. When I use the .Range(\"v1_copy

3条回答
  •  粉色の甜心
    2021-01-20 19:39

    Properly create ranges by using Set and don't refer to worksheets before them. Workbook-scoped ranges don't need to be tied to any worksheet.

    Sub copy_paste_test()
    
        Dim myCopyRange As Range
        Dim myPasteRange As Range
    
        Set myCopyRange = Range("v1_copy")
        Set myPasteRange = Range("v1_paste")
    
        Range("v1_paste").Value = Range("v1_copy").Value
        'myPasteRange.Value = myCopyRange.Value
    
    End Sub
    

提交回复
热议问题