+ Reply to Thread
Results 1 to 20 of 20

Add a Calculation by VBA

  1. #1
    Registered User
    Join Date
    08-18-2019
    Location
    maharashtra
    MS-Off Ver
    2013
    Posts
    14

    Add a Calculation by VBA

    Multiply the value of B2 by 1.5%, then multiply that result by 56 and then paste the result in D2(i need only result in the cell no formulas)
    note- 1st row contains headers so ignore the first row
    The file will be located in C:\Users\sk\Desktop and file name is sample.xlsx
    file is not opened so we have to open the file by vba and do the process and save it and close it
    vba will be added in a seperate file process.xlsm
    both files are located in same place
    i need vba to do the same

    Cross post link added
    http://www.vbaexpress.com/forum/show...Formula-by-vba
    Last edited by Richard Buttrey; 09-08-2019 at 05:53 AM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: calculation by vba

    http://www.vbaexpress.com/forum/show...ormula-by-vba&
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    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: calculation by vba

    If workbook 1 is the workbook in which you need the D2 cell populating, and this is being opened by a macro in workbook 2 then since workbook 1 will be the active file IMMEDIATELY your macro opens Workbook 1 then use somethig like the following as the bext line of code after the File Open instruction

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


    The reference to Sheet1 is the VBA Sheet code name NOT the sheet tab name which has the B2 value. Change as necessary
    I also assume that the B2 & D2 cells you're using are in both in Workbook1,
    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.

  4. #4
    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: calculation by vba

    Administrative Note:

    I added a solution before it was brought to my attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting.

    Add the links in your original post and I'll then re-open the solution I gave.

    Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)
    Last edited by Richard Buttrey; 09-08-2019 at 05:31 AM.

  5. #5
    Registered User
    Join Date
    08-18-2019
    Location
    maharashtra
    MS-Off Ver
    2013
    Posts
    14

    Re: calculation by vba

    i am unable to add a link in the post there is an error coming and i am unable to add the link in the post
    error u cant add any link or images until u post 2-3 post something like that sir

  6. #6
    Registered User
    Join Date
    08-18-2019
    Location
    maharashtra
    MS-Off Ver
    2013
    Posts
    14

    Re: http://www.vbaexpress.com/forum/showthread.php?65832-Formula-by-vba

    i was unable to add the link to this post so i changed topic name to the link sorry sir for the same but i am unable to add the link in the post due to an error

  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: calculation by vba

    Hi,

    I wasn't aware of a minimum 3 post limit, and in any case when you posted I think you had 5.

    However since you've adjusted the tite to include the link, and assuming that's the only other forum in which you've posted the link - if not plet me know, I'll add the link in your original.

  8. #8
    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: calculation by vba

    See post # 3 now displayed.

  9. #9
    Registered User
    Join Date
    08-18-2019
    Location
    maharashtra
    MS-Off Ver
    2013
    Posts
    14

    Re: Add a Calculation by VBA

    1.5% to .15 why i am unable to understand the same

  10. #10
    Registered User
    Join Date
    08-18-2019
    Location
    maharashtra
    MS-Off Ver
    2013
    Posts
    14

    Re: Add a Calculation by VBA

    Richard Sir plz prvide me the complete code for this problem
    i am unable to make the code for the same so plz have a look Sir and provide me the complete code

  11. #11
    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: Add a Calculation by VBA

    Put the code I gave you inside the Workbook Open event of workbook 2 as I defined it earlier i.e.

    Please Login or Register  to view this content.
    change the Sheet1 ref as necessary.

  12. #12
    Registered User
    Join Date
    08-18-2019
    Location
    maharashtra
    MS-Off Ver
    2013
    Posts
    14

    Re: Add a Calculation by VBA

    i have data upto 100 or 200 rows it can be more all it depends i have to do the same process till the end of the data

  13. #13
    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: Add a Calculation by VBA

    I see large mission creep from your first post.

    It's now not at all clear (at least to me) what it is you're trying to achieve. In any case this is clearly a much simplified example and probably doesn't represent the size of your actual data. We often find that when we give an answer to what is a trivial non representative example when the solution is used with the real world data it doesn't work because of factors like string length and other stuff which is important but hasn't been mentioned.

    Therefore upload your real workbook (or at least a cut down copy), and manually add the results you expect to see. Clearly identify which is original data and which are the results and in a note clearly explain how you have arrived at your results.

    One thing you must keep in mind when you ask a question in a forum... the people you are asking to help you know absolutely nothing about your data. Absolutely nothing about how it is laid out in the workbook, absolutely nothing about what you want done with it and absolutely nothing about how whatever it is you want done is to be presented back to you as a result.
    You must be very specific about describing each of these areas, in detail, and you should not assume that we will be able to "figure it out" on our own. Remember, you are asking us for help... so help us to be able to help you by providing the information we need to do so, even if that information seems "obvious" to you (remember, it is only obvious to you because of your familiarity with your data).

  14. #14
    Registered User
    Join Date
    08-18-2019
    Location
    maharashtra
    MS-Off Ver
    2013
    Posts
    14

    Re: Add a Calculation by VBA

    Plz see the attachments Sir
    Attached Files Attached Files

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try This ‼


    As using formula is the easy way even with VBA just needing a single codeline : [D2:D10] = [B2:B10*.84]

    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  16. #16
    Registered User
    Join Date
    08-18-2019
    Location
    maharashtra
    MS-Off Ver
    2013
    Posts
    14

    Re: Add a Calculation by VBA

    Sir But if the data is more than this then it will be a trouble for me bcoz data can be more or can be less we dont know but we can do the process till the end of data by vba so i am looking for that type of code

  17. #17
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Use CurrentRegion or UsedRange - to see in VBA inner help - combined to Rows & Columns …

    As you can also activate the Macro Recorder, open the workbook, add the formula to the first cell, copy down,
    close & save the workbook then post the generated code here
    - with the code tags or via icon as per forum rules -
    in order to get an optimization if really needed …

    But if it's only to be used once, a code is totally useless ! Just use a formula then Copy the result and PasteSpecials as value
    which is faster than creating a thread on any forum and waiting for someone may decypher your need …

  18. #18
    Registered User
    Join Date
    08-18-2019
    Location
    maharashtra
    MS-Off Ver
    2013
    Posts
    14

    Re: Add a Calculation by VBA

    Sir i will use this many times and second thing i am not a vba programmer like u sir
    i recorded the macro and i try to do it but i was unable to make the code
    i searched on google and i saw samples of vba code related to formula and i try to edit it but that code was also not workable
    i was getting error due to variables but there can be more error also in the code
    so i am looking for help
    code which i made (copied and edited) i deleted the same bcoz it was not working Marc Sir

  19. #19
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Add a Calculation by VBA

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  20. #20
    Registered User
    Join Date
    08-18-2019
    Location
    maharashtra
    MS-Off Ver
    2013
    Posts
    14

    Re: Add a Calculation by VBA

    Just now i posted the question to below link and i have mentioned the link in that forum
    https://www.mrexcel.com/forum/excel-...ation-vba.html
    I am following the forum rules Sir

+ 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. Replies: 10
    Last Post: 07-22-2019, 06:27 AM
  2. [SOLVED] VBA to open a workbook with manual calculation and close with automatic calculation
    By thedunna in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-04-2019, 12:28 PM
  3. [SOLVED] Calculation of dates and leaving blank cell when calculation sees non-date values
    By Hedy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-22-2018, 07:52 AM
  4. Replies: 0
    Last Post: 05-17-2014, 10:18 PM
  5. Replies: 1
    Last Post: 01-15-2013, 08:51 AM
  6. [SOLVED] Conditional statement calculation based on result of previous calculation.(Need some help)
    By takeprofit in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-01-2012, 01:45 AM
  7. Add an amount from a calculation to a cell with a calculation (Sample attached)
    By aiwnjoo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2010, 10:41 AM

Tags for this Thread

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