+ Reply to Thread
Results 1 to 2 of 2

overuse of the sentence ".Select" to perform various functions makes my program is slow

Hybrid View

  1. #1
    Registered User
    Join Date
    12-28-2012
    Location
    brazil
    MS-Off Ver
    Excel 2003
    Posts
    4

    overuse of the sentence ".Select" to perform various functions makes my program is slow

    Greetings all,

    I am conducting a financial program in VBA to estimate changes in securities, however overuse of the sentence. "Select" to perform various functions makes my program is slow. An example of this is the routine I use to copy the titles from one sheet to another.

    Sub CopiarTitulos()
    'Contar columnas en pestanna DVPrecios
        ultColumna = Sheets("DVPrecios").Cells(5, Columns.Count).End(xlToLeft).Column
       Sheets("DVVariaciones").Cells(1, "C") = ultColumna
       Sheets("DVVariaciones").Select
       Range("C5").Activate
        i = 3
    'Fin Contar columnas en pestanna DVPrecios
      
    'Copiar titulos en DVVariaciones
      While ultColumna >= i
        ActiveCell.FormulaR1C1 = "=IF(DVPrecios!RC<>""VALOR LIBROS"",DVPrecios!RC,"""")"
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        If Selection.Value = "" Then Selection.Delete Shift:=xlToLeft
        ActiveCell.Offset(0, 1).Select
        i = i + 1
    Wend
    
    Range("C5").Select
    Cells.EntireColumn.AutoFit
    ' Fin Copiar titulos en DVVariaciones
    End Sub
    This code works but if I have to copy the program 5,000 titles takes around 40 minutes to run. Please tell me how else I can write the code for me to select a specific cell and copy and paste the value or perform the various actions that need.

    Excuse my translation errors. My English is very bad
    Last edited by yosma; 01-03-2013 at 11:05 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: overuse of the sentence ".Select" to perform various functions makes my program is slo

    Can you describe VERBALLY what the macro is doing? I'm almost following it all, but want to confirm.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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