Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: Apply formula Calculation by VBA Value ="to Forumula"

  1. #1
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0

    Apply formula Calculation by VBA Value ="to Forumula"

    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
    https://www.mrexcel.com/forum/excel-...ation-vba.html
    http://www.vbaexpress.com/forum/show...Formula-by-vba
    https://www.excelforum.com/excel-pro...on-by-vba.html
    Last edited by DocAElstein; 06-24-2020 at 01:30 PM.

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Hello Avinash




    Quote Originally Posted by sumanjjj View Post
    1.5% to .15 why i am unable to understand the same
    I also do not understand....
    1.5% is 1.5/100 = .015
    Richard Buttrey ( https://www.excelforum.com/excel-pro...ml#post5190581 ) probably made typo mistake... just typo mistake - not important
    Sheet1.Range("D2") = Sheet1.Range("B2") * .15 * 56 is wrong
    Sheet1.Range("D2") = Sheet1.Range("B2") * .015 * 56 is correct



    Quote Originally Posted by sumanjjj View Post
    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
    So we need to make Lr dynamic, ( http://www.excelfox.com/forum/showth...ll=1#post11466 )
    For example …. Sample.xlsx : -
    http://www.excelfox.com/forum/showth...ll=1#post11474

    Quote Originally Posted by kaja
    , formula will be added by me in the code, put that formula in C2 and drag it the result will be shown by the formula in column C, …

    Multiply the value of B2 by 1.5%, then multiply that result by 56 and then paste the result in D2




    Quote Originally Posted by fixer View Post
    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…..formula will be added by me in the code, put that formula in …. drag it …….. the result will be shown by the formula )
    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


    So, I think requirement is
    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
    Multiply the value of B2 by 1.5%, then multiply that result by 56 and then paste the result in D2..formula will be added by me in the code, put that formula in ….
    drag it …….. the result will be shown by the formula

    I need only result in the cell no formulas…
    do the process and save it and close it

    note- 1st row contains headers so ignore the first row
    vba will be added in a seperate file process.xlsm
    both files are located in same place
    i need vba to do the same



    Using macro recorder, record macro
    Record Macro.JPG : https://imgur.com/I2gMvi9

    This is the macro recorded by the macro recorder:-
    Code:
    Sub Makro4()
    '
    ' Makro4 Makro
    '
    
    '   file is not opened so we have to open the file by vba
        Workbooks.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\vixer\sample.xlsx"
        
    '   Multiply the value of B2 by 1.5%, then multiply that result by 56 and then paste the result in D2..formula will be added by me in the code, put that formula in …
        Range("D2").Select
        ActiveCell.FormulaR1C1 = "=RC[-2]*(1.5/100)*56"
        
    '   drag it
        Range("D2").Select
        Selection.AutoFill Destination:=Range("D2:D10"), Type:=xlFillDefault
        
    '   I need only result in the cell no formulas
        Range("D2:D10").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        
    '   save it and close it
        Windows("sample.xlsx").Activate
        ActiveWindow.Close savechanges:=True
    End Sub
    Stop macro recording.JPG : https://imgur.com/F0ygnd2





    Here is a final macro written by me :-
    Code:
    '
    Sub Vixer9a() '  http://www.excelfox.com/forum/showthread.php/2369-Calculation-by-vba    https://www.mrexcel.com/forum/excel-questions/1109256-add-calculation-vba.html     http://www.vbaexpress.com/forum/showthread.php?65832-Formula-by-vba[/url]    https://www.excelforum.com/excel-pro...on-by-vba.html
    Rem 1 Workbook and worksheets info
    '1a) Workbook info
    ' Dim Wbm As Workbook: Set Wbm = ThisWorkbook ' The workbook containing macro
    Dim Wb1 As Workbook ' This will be set later when the workbook is opened
    Dim MyPath As String: Let MyPath = "C:\Users\sk\Desktop" '  ".....The file will be located in C:\Users\sk\Desktop ....
    Dim strWb1 As String: Let strWb1 = "sample.xlsx" '                                                          " ....and file name is sample.xlsx
    '1b) Worksheets info
    Dim Ws1 As Worksheet ' This will be set later when the workbook is opened)
    Dim Lr1 As Long '      Let Lr1 = 10 for sample file  , but we will determine it dynamically after opening the file
    Rem 2 Open file   "..... file is not opened so we have to open the file by vba
    ' Workbooks.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\vixer\sample.xlsx"
    ' Workbooks.Open Filename:=ThisWorkbook.Path & "" & strWb1  '  ...both files are located in same place
     Workbooks.Open Filename:=MyPath & "" & strWb1              '  ...file will be located in C:\Users\sk\Desktop
     Set Wb1 = ActiveWorkbook ' The workbook just opened will now be the current active workbook
     Set Ws1 = Wb1.Worksheets.Item(1)
    
    ' make Lr1 dynamic .... http://www.excelfox.com/forum/showth...ll=1#post11474    http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11474&viewfull=1#post11474  
     Let Lr1 = Ws1.Range("C" & Ws1.Rows.Count).End(xlUp).Row
    Rem 3 The Process ..."....
    '3(i) ....Multiply the value of B2 by 1.5%, then multiply that result by 56 and then paste the result in D2.. formula will be added by me in the code, put that formula in
     Ws1.Range("D2").Value = "=B2*(1.5/100)*56"
    '3(ii) ....drag it
     Ws1.Range("D2").AutoFill Destination:=Ws1.Range("D2:D" & Lr1 & ""), Type:=xlFillDefault
    '3(iii) I need only result in the cell no formulas
     Ws1.Range("D2:D" & Lr1 & "").Copy
     Ws1.Range("D2:D" & Lr1 & "").PasteSpecial Paste:=xlPasteValues
     Let Application.CutCopyMode = False
    Rem 4 save it and close it
     Wb1.Save
     Wb1.Close
    End Sub


    Alan

    ( see also here:

    http://www.excelfox.com/forum/showth...ll=1#post11473
    http://www.excelfox.com/forum/showth...ll=1#post11474
    )





    Ref
    Artik http://www.vbaexpress.com/forum/show...l=1#post394129
    Attached Files Attached Files
    Last edited by DocAElstein; 09-10-2019 at 11:44 PM.
    A Folk, A Forum, A Fuhrer ….

  3. #3
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Thnx Doc Sir and Each and Everyone for giving their Great Contribution,Support,Precious Time to all of my Problem's
    Have a Great Day

  4. #4
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Hello Avinash
    Here are some extra notes and further code examples:
    http://www.excelfox.com/forum/showth...ll=1#post11479
    http://www.excelfox.com/forum/showth...ll=1#post11484


    Alan

  5. #5
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Thnx Doc Sir for ur Great Efforts
    Doc Sir i am looking to buy a laptop i have serched on google and i have seen forums also but i have not got any exact answer for my question
    Sir i want to know which processor is best for laptop for vba only and graphics card are important or not
    and u r a Proffessional Programmer so Plz help us with the clear picture of which type of laptop or desktop is best for vba programming
    which type of configuration desktop or laptop is suitable for vba programming to achieve great performance(I know the speed of the vba programming depends on vba code but let us assume the code is best and we need to know about the configuration of desktop or laptop )
    Last edited by fixer; 09-16-2019 at 08:15 PM.

  6. #6
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Quote Originally Posted by fixer View Post
    …u r a Proffessional Programmer …
    No , this wrong
    I am a Builder. I build houses. I build now my castle in Germany
    मी एक बिल्डर आहे. मी घरे बांधतो. मी आता जर्मनी मध्ये माझा किल्ला तयार करतो
    I only do Excel for fun or for my private use
    मी फक्त गंमत म्हणून किंवा माझ्या खाजगी वापरासाठी Excel करतो

    I prefer older computers
    I buy an old lap top. ( Operating system XP or Vista )
    I buy an old large television.

    I use Excel 2003 , 2007 or 2010. ( Microsoft Office 2003, 2007 or 2010)

    I connect television to Lap top with HDMI cable ( or VGA cable )

    Use two monitors /Extended desktop
    XP: https://www.wikihow.com/Use-Extended...-in-Windows-XP
    https://www.youtube.com/watch?v=cr8T...ature=youtu.be

    Vista : https://www.instructables.com/id/How...crosoft-Vista/
    http://www.excelfox.com/forum/showth...ll=1#post11167
    https://www.youtube.com/watch?v=bfo3UyaS_j8
    http://www.excelfox.com/forum/showth...ll=1#post11167



    Then … Open Excel,
    Alt + F11

    Now you have Spreadsheet in high resolution on television, and VB Editor on lap top screen

    This is me at home now:
    Lap top is on table. 20190916_LapTop on Table.jpg : https://imgur.com/d4Bc5ZX
    20190916_LapTop on Table.jpg

    Television is hanging on the house wall 20190916_Television on Wall.jpg : https://imgur.com/FSSTVb6
    20190916_Television on Wall.jpg

    Now you have Spreadsheet in high resolution on television, and VB Editor on lap top screen:
    20190916_HDMI cable.jpg : https://imgur.com/aFWGKan
    20190916_HDMI cable.jpg




    Quote Originally Posted by fixer View Post
    Doc Sir i am looking to buy a lap top ….. let us assume the code is best …..
    My opinion.is

    If you have best code, then old cheap computer, + old cheap Television for extended second Monitor. Use XP or Vista Operating system. Use Excel 2003, or Excel 2007 or Excel 2010
    If you have best code then this is OK. Just is my opinion.

    Forget Windows 7 and Windows 10
    Forget Excel 2013 2016 and 365
    Forget New computer

    Buy an old laptop. Buy an old television ( for second Monitor)
    Buy old Office 2003 , 2007 and 2010

    All is just my opinion.




    Alan

    P.S. You can also ask this question here:
    https://www.excelforum.com/the-water-cooler/
    Last edited by DocAElstein; 11-15-2019 at 10:39 PM.
    A Folk, A Forum, A Fuhrer ….

  7. #7
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    No issue Sir i understood that any laptop will do but my question is vba what are the things which are the things that will make a process fast (90% of speed will depend on the code I agree on the same but 10% of the speed will depend on laptop configuration so plz let me know which type of laptop will be best for vba)

  8. #8
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    vba use how many cores of processor
    so how many cores processor will do etc like this way plz tell me and educate us and plz let me know that which configuration is best

  9. #9
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Quote Originally Posted by fixer View Post
    my question is vba what are the things which are the things that will make a process fast (90% of speed will depend on the code I agree on the same but 10% of the speed will depend on laptop configuration so plz let me know which type of laptop will be best for vba).....vba use how many cores of processor
    so how many cores processor will do etc like this way plz tell me and educate us and plz let me know that which configuration is best
    Sorry, I do not know the answer to those questions
    Alan

    P.S.
    Maybe ask here:
    https://www.excelforum.com/the-water-cooler/
    https://www.mrexcel.com/forum/genera...her-questions/
    https://www.mrexcel.com/forum/lounge-v-2-0/
    Last edited by DocAElstein; 09-18-2019 at 12:33 AM.

  10. #10
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    No Problem Sir
    Thnx Alot For ur Great Support Sir
    Have a Nice Day Sir

Similar Threads

  1. TAT Calculation
    By pramodagroiya in forum Excel Help
    Replies: 5
    Last Post: 05-30-2016, 12:27 PM
  2. On Going Calculation
    By justme1052 in forum Excel Help
    Replies: 2
    Last Post: 12-31-2013, 02:06 AM
  3. Replies: 5
    Last Post: 10-21-2013, 04:43 PM
  4. Calculation with different condition in a cell
    By LalitPandey87 in forum Excel Help
    Replies: 5
    Last Post: 04-04-2012, 08:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •