+ Reply to Thread
Results 1 to 13 of 13

Selecting a Cell in column "A", and finding where / If the cell exists in column D

  1. #1
    Registered User
    Join Date
    08-17-2014
    Location
    london
    MS-Off Ver
    2010
    Posts
    17

    Selecting a Cell in column "A", and finding where / If the cell exists in column D

    Hi,

    So I've been cracking on with my excel coding and feel like its all starting to make sense. A lot of what I do is checking data against other data, and one of the things I'm looking to do is to select the first cell in column A. I then want to look in column D, and work down to find when there is a match. Then this match occurs, it could highlight for instance or cut the cell and paste alongside the equivalent cell in Column A. This obviously then needs to be repeated for every value in row A. If the cell selected already matched, this is of course ok.

    I'm just looking for guidance really, this is what I have so far

    Please Login or Register  to view this content.
    How does this look? there is something wrong as it doesn't loop quite the way I would like it to, but I cant seem to get my head around it.

    Thanks again

    Alex

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    give this a shot

    Please Login or Register  to view this content.
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    FWIW:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-17-2014
    Location
    london
    MS-Off Ver
    2010
    Posts
    17

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    Thanks for all the help guys.

    So I have a modified version, split into two macros (I like to be able to do things in parts)

    The first highlights the cell in yellow in column D, if this cell is in column A. That all works fine.
    The second macro, i'm trying to get to go through column D, and find those cells not highlighted yellow, delete them and move the remaining cells upwards:
    Please Login or Register  to view this content.
    I know it is something to do with the way im working the loop in the 2nd macro - So i'm wondering if someone could explain why it isn't doing what I want it to do - and how to improve it.

    Thanks again guys!

  5. #5
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    I would try this.....completely untested...

    EDIT: I know it looks weird working from the bottom up, but when you are deleting data it actually seems to work better....
    John may know a better techique

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    Quote Originally Posted by AMWalton89 View Post
    Thanks for all the help guys.

    So I have a modified version, split into two macros (I like to be able to do things in parts)

    The first highlights the cell in yellow in column D, if this cell is in column A. That all works fine.
    The second macro, i'm trying to get to go through column D, and find those cells not highlighted yellow, delete them and move the remaining cells upwards:
    Please Login or Register  to view this content.
    I know it is something to do with the way im working the loop in the 2nd macro - So i'm wondering if someone could explain why it isn't doing what I want it to do - and how to improve it.

    Thanks again guys!
    I usually do this kind of matching in two sub parts because I always get errors if I combine the "then" aspect within the same loop. Would be nice to see the highlighting and subsequent deleting in one dirty loop. I mean DIRTY!

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    Pretty much the same as judgeh59.

    Please Login or Register  to view this content.
    I think both of the above codes need .Colorindex vrs .Color, but I haven't tested.
    Last edited by JOHN H. DAVIS; 09-18-2014 at 11:01 AM.

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    You can combine them if you want.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-17-2014
    Location
    london
    MS-Off Ver
    2010
    Posts
    17

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    Quote Originally Posted by JOHN H. DAVIS View Post
    Pretty much the same as judgeh59.

    Please Login or Register  to view this content.
    I think both of the above codes need .Colorindex vrs .Color, but I haven't tested.


    Thanks to Both of you. So my final code looks like this :

    Please Login or Register  to view this content.
    Can I ask a quick question. Can you explain what "To 2 Step -1" at the end of row is doing, as in the breakdown?

    Thanks again guys!

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    Increments by backwards rows

    From the last row:

    Please Login or Register  to view this content.
    To row 2.

    Please Login or Register  to view this content.
    One backwards step at a time

    Please Login or Register  to view this content.

  11. #11
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    To add to John's excellent explaination;

    In a FOR/NEXT loop the Step + 1 is generally implied....

    you can for example do

    Please Login or Register  to view this content.
    Obviously if you leave the Step option out, it defaults to 1

    HTH

    Thanks John

  12. #12
    Registered User
    Join Date
    08-17-2014
    Location
    london
    MS-Off Ver
    2010
    Posts
    17

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    Thanks for your time, its much appreciated!!

  13. #13
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Selecting a Cell in column "A", and finding where / If the cell exists in column D

    You're both welcome. Glad to help out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] filling cell in column "a" if data present in column "b" issue.
    By timmatthews in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-07-2013, 11:43 AM
  2. Replies: 1
    Last Post: 11-02-2013, 11:22 AM
  3. [SOLVED] If there is any text in column "A$" on "sheet1" then move cell to column "A$" on "sheet2"
    By ckgeary in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-27-2013, 08:28 PM
  4. [SOLVED] Delete row if cell in Column N equal "Different" or Column P equals "Blank"
    By Cyberpawz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2012, 08:25 AM
  5. Replies: 4
    Last Post: 03-12-2012, 10:46 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1