+ Reply to Thread
Results 1 to 8 of 8

Changing VBA code to work on different column

  1. #1
    Registered User
    Join Date
    10-31-2019
    Location
    Slovakia
    MS-Off Ver
    2016
    Posts
    14

    Changing VBA code to work on different column

    Hello, so I have this VBA code which works well, but now I need it to work on different columns.

    Please Login or Register  to view this content.
    Basically right now, it checks all cells in column A and if there are some with same name, it count their values in column C and then remove rows with duplicate names.

    Now what I need to change is that cell names will be in Column B and it count values in same column.

    So from A and C to B and C.
    Could you help me with this please?
    Last edited by Hecky83150; 03-13-2020 at 04:41 AM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Changing VBA code to work on different column

    How many rows of data do you have?
    Your code would is amazingly slow for any significant amount of rows.


    The "A" in these lines tells the code to look in column A. So Change "A" to "B"

    Please Login or Register  to view this content.
    The 2 in this line tells the code to increment the column two columns to the right of Column A

    Please Login or Register  to view this content.
    So if to are now looking at column B and want to increment column C the 2 needs to be a 1

    Please Login or Register  to view this content.


    Please Login or Register  to view this content.
    Last edited by mehmetcik; 03-09-2020 at 08:45 AM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    10-31-2019
    Location
    Slovakia
    MS-Off Ver
    2016
    Posts
    14

    Re: Changing VBA code to work on different column

    Hi, thanks for the reply.

    I have changed it to this but it seems to not work properly. It only remove 1 duplicate and ignore multiple ones.

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,637

    Re: Changing VBA code to work on different column

    You may try such (only slightly ammended) code:

    Please Login or Register  to view this content.
    I think the first code worked well only because in your file content of columns a and B was either the same or there were the same pairs. because you compared column A and B
    Please Login or Register  to view this content.
    As I don't like manipulating control variable in For ... Next loop, I also changed inner row counter to go bottom-up. This way deleted row changes nothing in current loop execution, because in next turn the code will check next row up anyway.

    Also, as mehmetcik mentioned such code will probably be rather slow in case of large datasets, with many duplicates. Probably the quickest (built in) way to deal with such situation will be Pivot Table.
    Best Regards,

    Kaper

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Changing VBA code to work on different column

    Apologies

    There is a much faster method using evaluate that I was trying to make work.

    In the interim. This code should be a lot faster than your original.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-31-2019
    Location
    Slovakia
    MS-Off Ver
    2016
    Posts
    14

    Re: Changing VBA code to work on different column

    Quote Originally Posted by mehmetcik View Post
    Apologies

    There is a much faster method using evaluate that I was trying to make work.

    In the interim. This code should be a lot faster than your original.

    Please Login or Register  to view this content.
    Looks good to me I don't mind using different code if it works.
    I've tried to execute this code, but it ran error

    Attachment 666515

    and highlighted this line
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-31-2019
    Location
    Slovakia
    MS-Off Ver
    2016
    Posts
    14

    Re: Changing VBA code to work on different column

    Thank you, this one works for my purpose. I think the biggest datasets are going to be maybe in thousands rows tops, do you think it will couse problems?

    When I've tried to run this with couple hundreds of datasets if worked fast I think, it was in about 1 second done.

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Changing VBA code to work on different column

    It is best to use this code. The evaluate function can only cope with 64000 rows.

+ 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. Testing single code, work fine. Put multiple codes in one sheet, one code doesn't work.
    By MayDay1988 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2017, 06:14 PM
  2. Changing code to work on entire sheet instead of specific columns
    By elmasguapo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2015, 06:02 PM
  3. Changing listbox code to work in a userform
    By cosmicwinds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2014, 01:52 PM
  4. Changing a code only to work on certain sheets
    By jshaw82 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-12-2013, 04:10 AM
  5. [SOLVED] Refering code to work on just one column
    By kjshep in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-24-2012, 12:52 PM
  6. Need help changing code to use a different column
    By luke.guthrie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-18-2012, 12:39 PM
  7. Changing Column values with VB code
    By 00Able in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-24-2011, 11:24 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