+ Reply to Thread
Results 1 to 4 of 4

Macro needs editing

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-26-2013
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2013
    Posts
    248

    Macro needs editing

    Hi. The below macro copies cells from columns R,S,T to another sheet. It deletes the last row of data. How can I change it so that it does not include the last row of data only if cell R6 in sheet "events exp up to 2 months" is an even number? For example, if R6=57 then clear
    Z = Sheets("P_L events up to 2 months").Range("B" & Rows.Count).End(3).Row
            Sheets("P_L events up to 2 months").Range(Cells(Z, "B"), Cells(Z, "D")).Clear
    If R6=56 don't clear.
    Sub copy_paste1()
        Dim i As Long, Y As Long, Z As Long
        With Application
            .ScreenUpdating = False: .Calculation = xlManual: .EnableEvents = False
        End With
            Sheets("P_L events up to 2 months").Select
            Range("B4:D20000").ClearContents
        
            Y = Sheets("events exp up to 2 months").Range("T" & Rows.Count).End(3).Row
            For i = 9 To Y
                With Sheets("P_L events up to 2 months")
                    .Range("B" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("R" & i).Value
                    .Range("C" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("S" & i).Value
                    .Range("D" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("T" & i).Value
                End With
            Next i
            Z = Sheets("P_L events up to 2 months").Range("B" & Rows.Count).End(3).Row
            Sheets("P_L events up to 2 months").Range(Cells(Z, "B"), Cells(Z, "D")).Clear
        With Application
            .EnableEvents = True: .Calculation = xlAutomatic: .ScreenUpdating = True
        End With
    End Sub
    Thanks for any help!

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,876

    Re: Macro needs editing

    Try this (Untested Code)

    Sub copy_paste1()
        Dim i As Long, Y As Long, Z As Long
        With Application
            .ScreenUpdating = False: .Calculation = xlManual: .EnableEvents = False
        End With
            Sheets("P_L events up to 2 months").Select
            Range("B4:D20000").ClearContents
        
            Y = Sheets("events exp up to 2 months").Range("T" & Rows.Count).End(3).Row
            For i = 9 To Y
                With Sheets("P_L events up to 2 months")
                    .Range("B" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("R" & i).Value
                    .Range("C" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("S" & i).Value
                    .Range("D" & Rows.Count).Eznd(3)(2).Value = Sheets("events exp up to 2 months").Range("T" & i).Value
                End With
            Next i
            Z = Sheets("P_L events up to 2 months").Range("B" & Rows.Count).End(3).Row
            If Application.WorksheetFunction.IsOdd(Worksheets("events exp up to 2 months").Range("R6").Value) Then Sheets("P_L events up to 2 months").Range(Cells(Z, "B"), Cells(Z, "D")).Clear
        With Application
            .EnableEvents = True: .Calculation = xlAutomatic: .ScreenUpdating = True
        End With
    End Sub
    Let me know if you have any issues.
    Cheers!
    Deep Dave

  3. #3
    Forum Contributor
    Join Date
    10-26-2013
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2013
    Posts
    248

    Re: Macro needs editing

    Thanks! This works!

  4. #4
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,876

    Re: Macro needs editing

    Glad it helps..

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. [SOLVED] I need help editing a Macro
    By ahovancsak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2015, 03:25 PM
  2. Macro Editing
    By christipper in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-13-2013, 07:24 AM
  3. Help editing a Macro
    By lostgrave2001 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 01-29-2013, 09:20 PM
  4. [SOLVED] Macro editing
    By Karnik in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-14-2013, 12:05 AM
  5. Need help with editing Macro
    By harpertorch in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-03-2012, 04:56 AM
  6. Help with editing one macro from another!
    By nrichardson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2012, 12:44 PM
  7. Editing Macro
    By heitorfjr in forum Excel General
    Replies: 1
    Last Post: 01-15-2006, 03:10 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