Google Answers Logo
View Question
 
Q: Cutting Cells in Excel ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Cutting Cells in Excel
Category: Computers
Asked by: gregbmelbaust-ga
List Price: $5.00
Posted: 05 Mar 2004 21:01 PST
Expires: 04 Apr 2004 22:01 PDT
Question ID: 313963
I wish to run a macro that will find a specified value in a range, say
C1:C9, when that value is found I want the macro to ?Cut? this value
as well as the value in the cell to the right, lets assume that the
specified value is 17 in cell C4, then highlight this and cell D4, Cut
and paste to C10, I?m using the
following example to do this..

Dim myCellPtr
    Dim myNew
         
    Set myNew = Range("C4:C9")
    For myCellPtr = 1 To myNew.Count
        If myNew(myCellPtr) = "17" Then
        myNew(myCellPtr).Cut
        Range("C10").Select
        ActiveSheet.Paste
        End If
    Next myCellPtr
    Set myNew = Range("C4:C9")
    For myCellPtr = 1 To myNew.Count
        If myNew(myCellPtr) = "18" Then
        myNew(myCellPtr).Cut
        Range("C11").Select
        ActiveSheet.Paste
        End If??.

How do I get the macro to select both cells i.e. C4 and D4?
Answer  
Subject: Re: Cutting Cells in Excel
Answered By: aht-ga on 05 Mar 2004 23:45 PST
Rated:5 out of 5 stars
 
Hello gregmalbaust-ga, and thanks for your Question!

For your specific example, what you will want to do in order to select
both the cell where the value is found, and the cell to the right of
it, is to replace the current line:

     myNew(myCellPtr).Cut

with the line:

    Range(myNew(myCellPtr), myNew(myCellPtr).Offset(0, 1)).Cut


The difference is to define a Range, following the pattern:

    Range(Cell1, Cell2)

      where Cell1 and Cell2 are, respectively, the upper-left and lower-right
      corners of the rectangular range (ex. A1 to C5)

and the Offset method of referencing a cell; in this case, offsetting
from myNew(myCellPtr) by zero rows down, one column right.

By extension, if you wanted to use this method to find an index value
in the first column of a table, then copy the value and the next six
cells to the right of the index value, you would use 'Offset(0,6)'. If
you want to select two rows' worth of the next six cells to the right,
you would use 'Offset(1,6)'. Just remember that, for the Offset
method, zero references the row and column of the referenced cell.

I hope this helps! If you would like some clarification to this
Answer, please let me know using the 'Request Clarification' button
above, before you rate and close this Question.

Good luck!

aht-ga
Google Answers Researcher
gregbmelbaust-ga rated this answer:5 out of 5 stars and gave an additional tip of: $5.00
Thanks works perfectly

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy