+ Reply to Thread
Results 1 to 12 of 12

Help turning a VBA Function/formula into a macro

  1. #1
    Registered User
    Join Date
    05-10-2021
    Location
    London
    MS-Off Ver
    10
    Posts
    9

    Help turning a VBA Function/formula into a macro

    Hi,

    Have this function code which sorts the contents of a single cell:
    Formula: copy to clipboard
    Please Login or Register  to view this content.



    Which then works by using this formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Is there a way to have a macro instead run this so that I don't need the excel formula. I'm using a different code to allow a data validation list to select more than one option at once but would like it to also sort the entries too. Thank you!

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Help turning a VBA Function/formula into a macro

    If you'll include a sample showing both before and after, in other words, what you want to achieve, it will help a lot in driving towards a solution.
    I know I'm not stupid, but I suspect I'm a lot stupider than I think I am

  3. #3
    Registered User
    Join Date
    05-10-2021
    Location
    London
    MS-Off Ver
    10
    Posts
    9

    Re: Help turning a VBA Function/formula into a macro

    Quote Originally Posted by jomili View Post
    If you'll include a sample showing both before and after, in other words, what you want to achieve, it will help a lot in driving towards a solution.
    How do I include a sample, I cant find an upload button on here

  4. #4
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Help turning a VBA Function/formula into a macro

    Yeah, the forum's had issues with that. Click into Advanced View then go down below and click on Manage Attachments. Then you can attach it.

  5. #5
    Registered User
    Join Date
    05-10-2021
    Location
    London
    MS-Off Ver
    10
    Posts
    9

    Re: Help turning a VBA Function/formula into a macro

    Its not letting me attach the file but here is the original cell:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This is the formula looking at that cell which uses the VBA function shown in original post:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    And the outcome:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Rather than use this formula and the function VBA code I need a macro which updates the original cell.

  6. #6
    Registered User
    Join Date
    05-10-2021
    Location
    London
    MS-Off Ver
    10
    Posts
    9

    Re: Help turning a VBA Function/formula into a macro

    Hopefully its attached to this message
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Help turning a VBA Function/formula into a macro

    Try this:

    Please Login or Register  to view this content.
    Almost forgot the function it works off of
    Please Login or Register  to view this content.
    Last edited by jomili; 06-27-2022 at 09:51 AM.

  8. #8
    Registered User
    Join Date
    05-10-2021
    Location
    London
    MS-Off Ver
    10
    Posts
    9

    Re: Help turning a VBA Function/formula into a macro

    This works perfectly thank you! I'm sorry one extra question on this, if I wanted to run the Sortwithincell code as part of the code I have attached to a worksheet change procedure, how can I attach it to that, I've listed below the private sub code normally attached to the tab code (rather than in a module). I tried just typing out Sorthwithincell but I get an error when it runs it.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 06-27-2022 at 10:49 AM. Reason: Please do not quote entire posts!

  9. #9
    Registered User
    Join Date
    05-10-2021
    Location
    London
    MS-Off Ver
    10
    Posts
    9

    Re: Help turning a VBA Function/formula into a macro

    Attached updated demo file with cell A1 with the data validation drop down, built in code which allows multiple selection and your code. Anyway to get the macro to run when the drop down code is selected and the change code is run.

    Thanks!
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Help turning a VBA Function/formula into a macro

    To call a macro from within a macro, and if both are in the same workbook, or in your PERSONAL.xlsb, all you need to do is put the macro name. So, in your massive Worksheet Change macro, you would slip in the name "SortWithinCell" wherever you wanted it to kick in. However since the "SortWithinCell" works by selection, you probably don't want to call the full macro. Probably delete these lines:
    Please Login or Register  to view this content.
    And change "For Each cell In rng" to "With Target", and change "next cell" to "End With".

  11. #11
    Registered User
    Join Date
    05-10-2021
    Location
    London
    MS-Off Ver
    10
    Posts
    9

    Re: Help turning a VBA Function/formula into a macro

    Very sorry don't worry, got it to work. I had to put the link to your macro within lines turning off enable events otherwise it was causing an endless loop of it sorting and rerunning the change event macro. My fault.

    Thank you though Jomili so much this is a massive help for me.

  12. #12
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Help turning a VBA Function/formula into a macro

    Glad I could help. If this fixes your issue don't forget to mark the thread "Solved" by using the Thread Tools at the top.

+ 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] Print function is turning up in an error
    By mdovey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2014, 06:59 AM
  2. turning a macro into a custom function
    By ryefield in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-09-2013, 03:11 PM
  3. [SOLVED] Turning a Macro into a VB Add-on
    By summerela in forum Excel - New Users/Basics
    Replies: 9
    Last Post: 09-28-2012, 07:46 PM
  4. Help turning a bit of subroutine into a function
    By tozjerimiah in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-26-2011, 11:56 AM
  5. Turning a worksheet algorithm into a suitable function
    By veracity in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-15-2010, 04:27 PM
  6. XIRR Function turning into =#N/A
    By jwskibum in forum Excel General
    Replies: 3
    Last Post: 04-01-2009, 11:53 AM
  7. Turning off the Exponent Function
    By Jeffn21 in forum Excel General
    Replies: 0
    Last Post: 01-10-2005, 12:04 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