Run-time error '1004' : Method 'Range&

2019-03-06 10:27发布

问题:

I'm just trying to do a simple cut and paste to shift ranges in F:G to an unoccupied cell in D but I keep getting that error message. My codes are in the Modules and I don't know what I'm doing wrong! Completely new to VBA. Highlighted portion: Range("F" & RowNum & ":G" & RowNum).Select

Sub MoveCells(RowNum as Integer)

   Range(“F” & RowNum & ":G" & RowNum).Select

   Selection.Cut

   Range(“D” & RowNum).Select

   ActiveSheet.Paste

End Sub

回答1:

Range(“F” & RowNum & ":G" & RowNum).Select
      ^ ^            ^  ^
      | |            |  |
    Chr(147)        Chr(34)

The 'quotation marks' around F are character 147. To denote a string value you have to use character 34, like the ones around :G

This usually happens when copy/pasting code from a website. Delete the quotation marks and re-write them manually to solve the issue.



标签: excel vba range