+ Reply to Thread
Results 1 to 6 of 6

SpeedUp/Alternative to Offset.Value = Offset.Value

Hybrid View

  1. #1
    Registered User
    Join Date
    08-17-2012
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    85

    SpeedUp/Alternative to Offset.Value = Offset.Value

    Is there an alternative to speed up this procedure :

    Sub AddToDB()
    
    Dim rV As Range
    Dim rDB As Range
    Dim row As Integer
    
    row = Sheets("DB").Cells(Rows.Count, 2).End(xlUp).row + 1
    Set rDB = Sheets("DB").Cells(row, 2)
    Set rV = Sheets("Valuation").Range("C4")
    
    rDB.Value = rV.Value
    rDB.Offset(0, 1).Value = rDB.Offset(0, 1).Value
    rDB.Offset(0, 4) = Date
    
    rDB.Offset(0, 5).Value = rV.Offset(10, 2).Value
    rDB.Offset(0, 6).Value = rV.Offset(11, 2).Value
    rDB.Offset(0, 7).Value = rV.Offset(12, 2).Value
    rDB.Offset(0, 8).Value = rV.Offset(13, 2).Value
    rDB.Offset(0, 9).Value = rV.Offset(14, 2).Value
    rDB.Offset(0, 10).Value = rV.Offset(15, 2).Value
    rDB.Offset(0, 11).Value = rV.Offset(16, 2).Value
    rDB.Offset(0, 12).Value = rV.Offset(17, 2).Value
    rDB.Offset(0, 13).Value = rV.Offset(18, 2).Value
    rDB.Offset(0, 14).Value = rV.Offset(19, 2).Value
    rDB.Offset(0, 15).Value = rV.Offset(20, 2).Value
    
    rDB.Offset(0, 16).Value = rV.Offset(31, 2).Value
    rDB.Offset(0, 17).Value = rV.Offset(27, 2).Value
    rDB.Offset(0, 18).Value = rV.Offset(30, 2).Value
    rDB.Offset(0, 19).Value = rV.Offset(32, 2).Value
    
    rDB.Offset(0, 20).Value = rV.Offset(4, 21).Value
    rDB.Offset(0, 21).Value = rV.Offset(7, 21).Value
    rDB.Offset(0, 22).Value = rV.Offset(14, 21).Value
    rDB.Offset(0, 23).Value = rV.Offset(16, 21).Value
    rDB.Offset(0, 24).Value = rV.Offset(22, 21).Value
    rDB.Offset(0, 25).Value = rV.Offset(25, 21).Value
    
    End Sub
    I am using it to add those values into database (another sheet), but it's very very slow.

    Thanks
    Last edited by Jovica; 12-13-2013 at 01:52 AM.

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: SpeedUp/Alternative to Offset.Value = Offset.Value

    Maybe:

    Sub AddToDB()
    
    Dim rV As Range
    Dim rDB As Range
    Dim row As Integer
    Application.Screenupdating = false
    row = Sheets("DB").Cells(Rows.Count, 2).End(xlUp).row + 1
    Set rDB = Sheets("DB").Cells(row, 2)
    Set rV = Sheets("Valuation").Range("C4")
    
    rDB.Value = rV.Value
    rDB.Offset(0, 1).Value = rDB.Offset(0, 1).Value
    rDB.Offset(0, 4) = Date
    
    rDB.Offset(0, 5).Resize(,11).Value = rV.Offset(10, 2).Resize(11).Value
    
    rDB.Offset(0, 16).Resize(,4).Value = Array(rV.Offset(31, 2).Value, rV.Offset(27, 2).Value, rV.Offset(30, 2).Value, rV.Offset(32, 2).Value)
    
    rDB.Offset(0, 20).Value = rV.Offset(4, 21).Value
    rDB.Offset(0, 21).Value = rV.Offset(7, 21).Value
    rDB.Offset(0, 22).Value = rV.Offset(14, 21).Value
    rDB.Offset(0, 23).Value = rV.Offset(16, 21).Value
    rDB.Offset(0, 24).Value = rV.Offset(22, 21).Value
    rDB.Offset(0, 25).Value = rV.Offset(25, 21).Value
    Application.Screenupdating = true
    
    End Sub

  3. #3
    Registered User
    Join Date
    08-17-2012
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: SpeedUp/Alternative to Offset.Value = Offset.Value

    Thanks, it's much faster but this line doesn't work
    rDB.Offset(0, 5).Resize(,11).Value = rV.Offset(10, 2).Resize(11).Value
    Only the first value rV.Offset(10, 2) is copied into next 11 cells.

    ...
    changed that line with copy (11 cells) /paste values transpose=true and it's still slow.
    Last edited by Jovica; 12-12-2013 at 03:37 PM.

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: SpeedUp/Alternative to Offset.Value = Offset.Value

    Oh, right, forgot about that. Try changing to:
    rDB.Offset(0, 5).Resize(,11).Value = Application.Tranpose(rV.Offset(10, 2).Resize(11).Value)

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

    Cool Try this :

    Sub AddToDB()
        Dim rDB As Range
                           Set rDB = Sheets("DB").Cells(Sheets("DB").Rows.Count, 2).End(xlUp)(2)
        Application.ScreenUpdating = False
    
        With Sheets("Valuation")
                                rDB.Value = .[C4].Value
                          rDB(1, 2).Value = rDB(1, 2).Value
                          rDB(1, 5).Value = Date
             rDB(1, 6).Resize(, 11).Value = Application.Transpose(.[E14:E24].Value)
    
            rDB(1, 17).Resize(, 10).Value = Array(.[E35].Value, .[E31].Value, .[E34].Value, _
                                                  .[E36].Value, .[X8].Value, .[X11].Value, _
                                    .[X18].Value, .[X20].Value, .[X26].Value, .[X29].Value)
        End With
                           Set rDB = Nothing
        Application.ScreenUpdating = True
    End Sub
    Last edited by Marc L; 12-12-2013 at 10:55 PM.

  6. #6
    Registered User
    Join Date
    08-17-2012
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: SpeedUp/Alternative to Offset.Value = Offset.Value

    Wow, much faster. Thank you so much!
    I'll try to reverse engineer this into my other macros.

+ 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. How to create dynamic ranges, better alternative to OFFSET
    By JamesGoulding85 in forum Excel General
    Replies: 2
    Last Post: 06-04-2013, 03:27 PM
  2. [SOLVED] Alternative to kloojy use of OFFSET
    By wolfgang713 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 05-31-2013, 02:51 PM
  3. Alternative to Offset in a formula
    By ashokunbi in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-22-2013, 08:33 PM
  4. [SOLVED] Sumproduct Offset alternative needed
    By samshiells in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-06-2012, 12:18 PM
  5. Alternative for #N/A in an offset and match formula?
    By carlos2011 in forum Excel General
    Replies: 8
    Last Post: 03-17-2011, 07:10 AM

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