+ Reply to Thread
Results 1 to 9 of 9

Execute formula for range

  1. #1
    Forum Contributor
    Join Date
    07-06-2006
    Posts
    108

    Execute formula for range

    Dear community,

    I managed to come up with the below code.

    Please Login or Register  to view this content.
    This will trim the value for a particular cell. Now I want to expand this coding to work for each cell which is not empty in column A.

    What is the best way to handle this?
    Attached Images Attached Images
    Last edited by TomBP; 02-23-2018 at 04:19 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Execute formula for range

    Hi,

    Try

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

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Execute formula for range

    Just curious, but why are you doing this with a macro?

    You could simply put the TRIM formula in an adjacent cell, fill down and then copy/paste special values over the originals and remove the formula.

    The above observation is of course based on the likely narrow scope you have given us. If your overall goal goes far beyond this, instead of asking small questions for each step along the way of coding what you are trying to do, just share the overall goal so we can give the best overall guidance and help possible. By asking as you go, the responses you get cannot factor in the other parts of your goal, so part A may not be conducive to what you need in part C, etc.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  4. #4
    Forum Contributor
    Join Date
    07-06-2006
    Posts
    108

    Re: Execute formula for range

    Quote Originally Posted by Zer0Cool View Post
    Just curious, but why are you doing this with a macro?

    You could simply put the TRIM formula in an adjacent cell, fill down and then copy/paste special values over the originals and remove the formula.

    The above observation is of course based on the likely narrow scope you have given us. If your overall goal goes far beyond this, instead of asking small questions for each step along the way of coding what you are trying to do, just share the overall goal so we can give the best overall guidance and help possible. By asking as you go, the responses you get cannot factor in the other parts of your goal, so part A may not be conducive to what you need in part C, etc.
    The goal is to TRIM multiple columns and I don't know what the row length will be in advance.

    Creating adjacent columns and fill down the formula would be too much of a hassle.

    I'm also not using a "simple" TRIM function but the below formula. How this needs to be translated into VBA is something I have yet to figure out.

    =TRIM(CLEAN(SUBSTITUTE(A2;CHAR(160);" ")))
    Last edited by TomBP; 02-19-2018 at 04:33 AM.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Execute formula for range

    What do you mean by 'translated into VBA?'

    Do you mean you want VBA to create that formula and enter it on the sheet, or that you want the result of such a formula to appear. If the latter then my last post shows one way.

  6. #6
    Forum Contributor
    Join Date
    07-06-2006
    Posts
    108

    Re: Execute formula for range

    Quote Originally Posted by Richard Buttrey View Post
    What do you mean by 'translated into VBA?'

    Do you mean you want VBA to create that formula and enter it on the sheet, or that you want the result of such a formula to appear. If the latter then my last post shows one way.
    I mean that I want the result of such a formula to appear. You are correct that your earlier post shows a way and actually works. Kudos to you.

    When I say translate to VBA, I mean the following: I was hoping that my sample case with the test data would be easily transferred to my actual formula. I thought the below coding would do the trick, but apparently it still needs some tweaking.

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

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Execute formula for range

    It's still not clear, at least to me. Are you wanting an Excel fomula on the sheet or some VBA code?

    Perhaps it would help if you uploaded an example workbook and manually add the results you expect. Be sure to explain which is original data and which are the required results,

    I was also puzzled by your earier reference about having the solution applied to all cells that aren't empty. Since the essence of the task is to trim some characters from sells then I don't see why you want to try and distinguish blank cells since trimming a blank cell will simply leave the blank untouched.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Execute formula for range

    All of those functions would require a range passed to them, not an array, so you cannot nest them like that. You might use Evaluate like this
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  9. #9
    Forum Contributor
    Join Date
    07-06-2006
    Posts
    108

    Re: Execute formula for range

    Quote Originally Posted by xlnitwit View Post
    All of those functions would require a range passed to them, not an array, so you cannot nest them like that. You might use Evaluate like this
    Please Login or Register  to view this content.
    That's exactly what I needed. Thx

+ 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] If CELL is blank the execute formula1, IF Cell is not blank execute formula 2
    By grahamlees in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-13-2017, 06:47 AM
  2. Execute a macro in a closed workbook, or open and execute without the user noticing
    By cearaujo123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-09-2015, 06:44 PM
  3. code to execute a keyboard shortcut or to execute a toolbar button
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2015, 12:16 PM
  4. [SOLVED] VBA code required not to execute during certain date and time range
    By mchilapur in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-15-2015, 08:57 PM
  5. [SOLVED] Change From Execute on Selections to Execute On All
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2014, 09:23 AM
  6. Unable to execute formula on a range of cells that are also formulas
    By Crysizzle in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-24-2013, 11:22 AM
  7. Defining an extra range to execute a different input change
    By ScottyDo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-07-2012, 02:19 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