Results 1 to 7 of 7

Selection.ClearContents - VBA

This is a discussion on Selection.ClearContents - VBA within the Excel Questions forums, part of the Question Forums category; hello all im trying to clear some cells using VBA the first ones work on the run to product line ...

  1. #1
    Board Regular
    Join Date
    Apr 2003
    Posts
    358

    Default Selection.ClearContents - VBA

    hello all

    im trying to clear some cells using VBA
    the first ones work on the run to product line , but why cant i get the others to work?
    do i need a link or somthing to link them together ?

    Code:
    'RUN TO PRODUCT
          Range("J25,J38,J51,J64,J77,J90,J103,J116,J129,J142,J155,J168,J181,J194,J207").Select
          Selection.ClearContents
    
    'CLEAR COMMENTS
          Range("J24,J37,J50,J63,J76,J89,J102,J115,J128,J141,J154,J167,J180,J193,J206").Select
          Selection.ClearContents
       
    'CLEAR COMMENTS
          Range("J23,J36,J49,J62,J75,J87,J101,J114,J127,J140,J153,J166,J179,J192,J205").Select
          Selection.ClearContents

    many thanks jason

  2. #2
    VoG
    VoG is offline
    MrExcel MVP
    Moderator
    VoG's Avatar
    Join Date
    Jun 2002
    Location
    127.0.0.1
    Posts
    62,770

    Default Re: Selection.ClearContents - VBA

    Do you mean CLEAR COMMENTS as opposed to CLEAR CONTENTS?

    Code:
    'RUN TO PRODUCT
          Range("J25,J38,J51,J64,J77,J90,J103,J116,J129,J142,J155,J168,J181,J194,J207").ClearContents
    
    'CLEAR COMMENTS
          Range("J24,J37,J50,J63,J76,J89,J102,J115,J128,J141,J154,J167,J180,J193,J206").ClearComments
       
    'CLEAR COMMENTS
          Range("J23,J36,J49,J62,J75,J87,J101,J114,J127,J140,J153,J166,J179,J192,J205").ClearComments
    HTH, Peter
    Please test any code on a copy of your workbook.

  3. #3
    Board Regular
    Join Date
    Jul 2004
    Location
    Elkhart, Indiana
    Posts
    898

    Default Re: Selection.ClearContents - VBA

    Jason - can you be more specific about what is not working?

    When I copied your code into a workbook, the code seemed to work properly. The values from cells J23, J24, J25, J36, J37, J38 ... etc were all cleared. Is there something else that you are trying to clear from the cells besides their values?

  4. #4
    PCL
    PCL is offline
    Board Regular
    Join Date
    Jul 2008
    Location
    France Alsace
    Posts
    939

    Default Re: Selection.ClearContents - VBA

    For me it's running in the active sheet: CONTENTS REMOVED
    You could simplify using
    Code:
          Range("J25,J38,J51,J64,J77,J90,J103,J116,J129,J142,J155,J168,J181,J194,J207").ClearContents

  5. #5
    Board Regular
    Join Date
    Apr 2003
    Posts
    358

    Default Re: Selection.ClearContents - VBA

    hello sorry folks

    Im trying to clear the contents on all the cells specified.

    The run to product line works, but the two clear comment lines don't clear the contents.

    thanks jason

  6. #6
    Board Regular
    Join Date
    Apr 2003
    Posts
    358

    Default Re: Selection.ClearContents - VBA

    is it because im trying to delete in a merge cell?

  7. #7
    Board Regular
    Join Date
    Apr 2003
    Posts
    358

    Default Re: Selection.ClearContents - VBA

    MANY THANKS FOLKS

    PCL thanks and it was because i had a couple of merged cells in it, sorry for the trouble

    jason

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com