Results 1 to 5 of 5

Efficient multiplication in VBA with macros

Threaded View

  1. #1
    Registered User
    Join Date
    03-07-2019
    Location
    Argentina
    MS-Off Ver
    Windows 10
    Posts
    4

    Efficient multiplication in VBA with macros

    Hello friends, I am trying to create a code that is as efficient as possible.

    What I need to do is Multiply a range of cells by a fixed value and then replace the value that each cell had with that new value.

    For example:

    In the "D5: 25" range I have different numerical values in each of the cells. Then I multiply each cell by a fixed value and that new value is replaced in each cell (I mean in the range "D5: 25").

    I was able to solve it through two ways, but both are "inefficient", since when I run the code it shows that it takes a long time to perform all the multiplication in that range.

    And also as I then need to do the same in other ranges too, I know that this code will not be efficient because it will take a long time.

    I pass the two codes that do work but are inefficient.

    Code 1:

    Sub dolartopesos()
    'Routine to pass to pesos all the prices of the products of each supplier that are in dollars.
    
    dollars = Worksheets(3).Range("R1")
    
    '---------------------------------------------------
    
    With Worksheets(3)
    'Currency exchange
    
    For i = 5 To 25
    
    .Cells(i, 4) = .Cells(i, 4) * dollars
    
    Next i
    
    
    End With
    
    
    '---------------------------------------------------
    
    End Sub


    Code2:

    Sub dolartopesos()
    'Routine to pass to pesos all the prices of the products of each supplier that are in dollars.
    
    dollars = Worksheets(3).Range("R1")
    
    '---------------------------------------------------
    ''Currency exchange
    
    Dim rng As Range: Set rng = Worksheets(3).Range("D5:25")
    Dim cel As Range
    For Each cel In rng.Cells
    With cel
    cel = Application.WorksheetFunction.Product(cel, dollars)
    End With
    Next cel
    
    '---------------------------------------------------
    End Sub


    Both codes take too long to multiply in that range.

    What could I do to speed up the multiplication?

    Any contribution will be welcome. From already thank you very much.

    Sebastian.
    Last edited by purinqui; 04-25-2020 at 02:26 AM. Reason: tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Vba for multiplication
    By winmaxservices in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2019, 10:28 AM
  2. [SOLVED] Sum of multiplication and add-up
    By Seifptv in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-19-2018, 07:42 PM
  3. [SOLVED] More Efficient: Calling smaller macros or one Big macro?
    By jakegordon97 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-19-2018, 05:40 PM
  4. what is the most efficient way to lookup in macros?
    By dwx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2015, 01:37 AM
  5. New to Excel Programming and need help making my macros more efficient
    By odoualex in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-01-2013, 11:01 AM
  6. Replies: 6
    Last Post: 04-21-2011, 01:12 PM
  7. Multiplication
    By kmarie630 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-25-2009, 03:59 PM

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