+ Reply to Thread
Results 1 to 11 of 11

Macro to find the lowest value and cut/insert to a different cell

  1. #1
    Registered User
    Join Date
    12-01-2017
    Location
    Singapore
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2212 Build 16.0.15928.20196) 64-bit
    Posts
    8

    Macro to find the lowest value and cut/insert to a different cell

    Hello to the VBA pros here,

    Is it possible for VBA macro to do this?
    I wish to highlight a section of cells and have it automatically select the lowest value out of each row, cut that cell and 1 cell to it's right and have it be inserted to the Z column.

    It's basically a bunch of prices and vendor names listed to the right of the price and i want to take the lowest price and have it be cut and inserted (has to be the insert function instead of paste) to the Z column, just by highlighting the cells i want the macro to affect.

    Example of my worksheet. I high-lite this entire thing and hit the macro.

    |12.00|vendor A|22.00|vendor B|15.00|vendor C
    | 5.00|vendor A| 7.00|vendor B| 8.00|vendor C
    |45.00|Vendor A|45.00|Vendor B|40.00|Vendor C <------ (I have no idea how the macro will affect prices that are the same, maybe have it ignore same prices and i will pick manually)

    Seems like quite a complicated macro. Appreciate it if any experts here can figure it out.

  2. #2
    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,697

    Re: Macro to find the lowest value and cut/insert to a different cell

    1) do you really need a macro to do this - can be domne with formulas (may be not real cutting, but listing lowest value and text (name) right to it.
    2) how about 2 (or more) equal lowest values in a row)
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    12-01-2017
    Location
    Singapore
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2212 Build 16.0.15928.20196) 64-bit
    Posts
    8

    Re: Macro to find the lowest value and cut/insert to a different cell

    Cause ultimately i want to actually move all the lowest value to one column for easy reference and to do calculations with formulas.

  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,697

    Re: Macro to find the lowest value and cut/insert to a different cell

    Try such code (made simple - will not be quick for large datasets):


    Please Login or Register  to view this content.
    Attached Images Attached Images

  5. #5
    Registered User
    Join Date
    12-01-2017
    Location
    Singapore
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2212 Build 16.0.15928.20196) 64-bit
    Posts
    8

    Re: Macro to find the lowest value and cut/insert to a different cell

    Close but not quite. Attached file.

    I want to highlight I3 to N16 (or how many more vendors there are) and hit the macro. And it will move the lowest value and the corresponding vendor to the I and J column.

    Hope it's clear enough to understand what i'm trying to do.
    Attached Files Attached Files
    Last edited by Kyoukami; 12-06-2017 at 05:59 AM.

  6. #6
    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,697

    Re: Macro to find the lowest value and cut/insert to a different cell

    please use attachment on the forum.

    SMALL sample Excel workbook(s) (10-20 rows of data is usually enough) Please don't attach a picture of one (no-one will want to re-type all your stuff before starting).

    1. Make sure that your sample data are truly REPRESENTATIVE of your real data. (If trere are typical cases like: all unique values/duplicates could occur, day/night, nobody present/several persons at once, before/on/past due, etc. - please show them all or at least indicate in text) The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired solution(s) is/are also shown (mock up the results manually). (also try showing the final (ultimate) step)

    3. Make sure that all confidential/restricted information (either personal or business) like real e-mails, social security numbers, bank accounts, etc. is removed first!!

    To attach an Excel file you have to do the following: Just before posting, scroll down and press Go Advanced button and then scroll down and press Manage Attachments link. Now follow the instructions at the top of that pop-up screen.

  7. #7
    Registered User
    Join Date
    12-01-2017
    Location
    Singapore
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2212 Build 16.0.15928.20196) 64-bit
    Posts
    8

    Re: Macro to find the lowest value and cut/insert to a different cell

    Quote Originally Posted by Kaper View Post
    please use attachment on the forum.

    SMALL sample Excel workbook(s) (10-20 rows of data is usually enough) Please don't attach a picture of one (no-one will want to re-type all your stuff before starting).

    1. Make sure that your sample data are truly REPRESENTATIVE of your real data. (If trere are typical cases like: all unique values/duplicates could occur, day/night, nobody present/several persons at once, before/on/past due, etc. - please show them all or at least indicate in text) The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired solution(s) is/are also shown (mock up the results manually). (also try showing the final (ultimate) step)

    3. Make sure that all confidential/restricted information (either personal or business) like real e-mails, social security numbers, bank accounts, etc. is removed first!!

    To attach an Excel file you have to do the following: Just before posting, scroll down and press Go Advanced button and then scroll down and press Manage Attachments link. Now follow the instructions at the top of that pop-up screen.
    I have edited my post to explain exactly what i want to achieve and attached a sample file.

  8. #8
    Registered User
    Join Date
    12-02-2017
    Location
    India
    MS-Off Ver
    2007
    Posts
    16

    Re: Macro to find the lowest value and cut/insert to a different cell

    This seems to work.

    May require some fine tuning and error handling as per your requirements.

    Please Login or Register  to view this content.

  9. #9
    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,697

    Re: Macro to find the lowest value and cut/insert to a different cell

    This shall work too (I started it earlier, but had to leave the office). If there are 2 or more minimal values all will be moved to column I, K, etc.
    Mote that moving cells can make your formula referring to column I invalid. To make it independant on moving cells you could either use MIN (you anyway look for lovest value) or INDIRECT function inside your CEILING
    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    12-01-2017
    Location
    Singapore
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2212 Build 16.0.15928.20196) 64-bit
    Posts
    8

    Re: Macro to find the lowest value and cut/insert to a different cell

    Quote Originally Posted by Kaper View Post
    This shall work too (I started it earlier, but had to leave the office). If there are 2 or more minimal values all will be moved to column I, K, etc.
    Mote that moving cells can make your formula referring to column I invalid. To make it independant on moving cells you could either use MIN (you anyway look for lovest value) or INDIRECT function inside your CEILING
    Please Login or Register  to view this content.
    Works amazing!! Would love to give you more rep but can't for now

  11. #11
    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,697

    Re: Macro to find the lowest value and cut/insert to a different cell

    Glad to hear it's working
    Reputation is nice, but it's not as important as satisfaction

    Would be lovely if you edit your post (as a matter of fact previous one too), to follow https://www.excelforum.com/forum-rul...rum-rules.html Rule 12

+ 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] how to find the lowest to highest value and display the name who is the lowest and the hig
    By jasond1992 in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 09-23-2015, 09:20 PM
  2. Replies: 4
    Last Post: 01-07-2014, 03:38 AM
  3. Copy the entire lowest row > Select the row below said row > Insert copied cell
    By saturos in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2013, 11:22 AM
  4. VBA macro Find & Copy the five highest and lowest value and paste it to a Table
    By genera74 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2013, 09:55 PM
  5. [SOLVED] Need Macro to find cell and insert a row above it.
    By Dnakr in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-23-2013, 03:17 PM
  6. macro to find first blank cell in rows and insert text
    By jlm13 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-21-2010, 06:27 PM
  7. Find lowest number in groups then lowest overall.
    By swieduwi in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-24-2008, 01:00 PM

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