Results 1 to 3 of 3

Thread: VBA Error

  1. #1
    Star Lounger
    Join Date
    Apr 2002
    Location
    New York, New York, USA
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA Error

    I hope someone can figure out what’s going on, because I am totally puzzled.

    I copy a list of names in Sheet2 Col B to Sheet1 Col C. I used the following code:

    Range("B1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Sheet1").Select
    Range("C2").Select
    ActiveSheet.Paste

    which works just fine. The number of names is variable, so I thought it would be a good idea to clear the names from Sheet1, Col C before I paste the new names. So I inserted the following statements just before the ActiveSheet.Paste statement:

    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("C2").Select

    but with those 3 statements inserted, the macro fails with a 400 error on the ActiveSheet.Paste statement.

    Can anyone figure out what’s going on?
    Thanks

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    I suspect that you get that error since the clipboard probably gets cleared.

    Try this. It should be faster as it does not selecting:

    Code:
    Worksheets("Sheet1").Columns("C").ClearContents
    With Worksheets("Sheet2")
    .Range(.Range("B1"), _
    .Range("B1").End(xlDown)).Copy _
    Worksheets("Sheet1").Range("C2")
    End With
    Steve

  3. #3
    Star Lounger
    Join Date
    Apr 2002
    Location
    New York, New York, USA
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so much - it worked perfectly.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •