+ Reply to Thread
Results 1 to 5 of 5

Improving existing VBA code and removal of unwanted row

Hybrid View

Narasimharao Nandula Improving existing VBA code... 09-03-2013, 05:24 AM
AB33 Re: Improving existing VBA... 09-03-2013, 06:03 AM
Narasimharao Nandula Re: Improving existing VBA... 09-03-2013, 06:41 AM
Narasimharao Nandula Re: Improving existing VBA... 09-03-2013, 06:47 AM
AB33 Re: Improving existing VBA... 09-03-2013, 09:56 AM
  1. #1
    Registered User
    Join Date
    04-23-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    56

    Improving existing VBA code and removal of unwanted row

    Dear All,

    I have managed to make a code for one of our local requirement and it works. I have bunch of different formula's in the row 8 of the sheet between "A:E" and "G:FD" which are connected to several independent sheets. My requirement is of copy of each formula (between "A:E" and "G:FD") till last row of Column "F". Column F data is copied from some other sheet. So that data should not get disturbed.

    However there are 2 problems in the code which are defined below:

    1) Code is very slow when no. of rows in the sheet are more than 200, no of rows some times go to the tune of 20,000.
    2) Code creates last row with blank values. I tried my best to remove this row with the code but could not succeed.

    Kindly suggest corrections and faster execution of the code.

    Look forward for the advise.

    best regards,
    Narasimharao

    Sub Copyformula()
    Dim NextRow As Long
    Dim Data1, Data2, Data3 As String
    Data1 = "Formula1"
    Data2 = "Formula2"
    Data3 = "Formula3"
    Dim l As Long
    Dim lRow As Long
    Dim Counter As Integer
    
    Worksheets("Sheet1").Activate
    ActiveSheet.Range("A9:E20000").ClearContents
    ActiveSheet.Range("G9:FD20000").ClearContents
    
    lRow = Range("F" & Rows.Count).End(xlUp).Row
    Counter = 1
    
    For l = 2 To lRow
    Counter = Counter + 1
    
        If Range("F" & l).Value <> "" Then
            
        Worksheets("Sheet1").Range("Formula1").Copy _
        Destination:=Worksheets("Sheet1").Cells(Counter + 1, 1).Offset(0, 0)
            
        Worksheets("Sheet1").Range("Formula2").Copy _
        Destination:=Worksheets("Sheet1").Cells(Counter + 1, 7).Offset(0, 0)
        
        Worksheets("Sheet1").Range("Formula3").Copy _
        Destination:=Worksheets("Sheet1").Cells(Counter + 1, 17).Offset(0, 0)
           
        End If
    Next l
        MsgBox "Done, Please proceed to Next Step"
    End Sub

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Improving existing VBA code and removal of unwanted row

    Untested.

    Sub macro_11112()
    Application.ScreenUpdating = 0
    With Sheets("Sheet1")
       .Range("A8:E8").Resize(.Cells(.Rows.Count, "F").End(xlUp).Row, 5).FillDown
       .Range("G8:FD8").Resize(.Cells(.Rows.Count, "F").End(xlUp).Row, 160).FillDown
    End With
     Application.ScreenUpdating = True
    End Sub

  3. #3
    Registered User
    Join Date
    04-23-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Improving existing VBA code and removal of unwanted row

    Hi AB33

    Once again thank you for prompt reply. I could use above code. in column F data is from F8. So when i use the code, 7 additional rows are created. Bold letter portion "F" needs corrections. Could you please suggest alternatives?

    Thanks again.
    Narasimharao

     .Range("A8:E8").Resize(.Cells(.Rows.Count, "F").End(xlUp).Row, 5).FillDown

  4. #4
    Registered User
    Join Date
    04-23-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Improving existing VBA code and removal of unwanted row

    Hi AB33

    I have managed to correct the code. THank you once again for your support and i am very happy for your continuous support again and again. Really my knowledge is improved with your support.

    Best Regards,
    Narasimharao

    Corrected code is as follows:
    Application.ScreenUpdating = 0
        With Sheets("ProMIS Projects Financial data")
       .Range("A8:E8").Resize(.Cells(.Rows.Count, "F").End(xlUp).Row - 7, 5).FillDown
       .Range("G8:FD8").Resize(.Cells(.Rows.Count, "F").End(xlUp).Row - 7, 160).FillDown
        End With
        Application.ScreenUpdating = True

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Improving existing VBA code and removal of unwanted row

    Narasimharao,
    Well done!
    Yes, I forget to deduct the first 7 rows as my rows count goes from 1 to the bottom.

+ 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. improving code by removing select
    By Zealotwraith in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-31-2013, 04:13 PM
  2. [SOLVED] Like some ideas on improving code on long IF statement used in VBA code please
    By dawatcher in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-12-2013, 01:44 PM
  3. Replies: 0
    Last Post: 05-25-2011, 09:28 AM
  4. Improving this set of code.
    By Ra21V12eN in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-11-2008, 06:21 PM
  5. employee planner, improving existing model
    By hole_alex in forum Excel General
    Replies: 1
    Last Post: 04-01-2007, 02:51 PM

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