Results 1 to 4 of 4

Insert Rows between unlkike cells, copy paste, then delete

Threaded View

  1. #1
    Registered User
    Join Date
    06-04-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    36

    Insert Rows between unlkike cells, copy paste, then delete

    Copy of Resource Allocation.xlsName_Sort.xlsHi There, I have created a small example of what I would like to achieve, see Name_Sort code below or the attached workbook. My question is, why does it not work whem implemented in "Copy of Resource Allocation", code below also attached. I just do not understand where my problem in Resource Allocation is. There seems to be an issue with inserting and removing the rows but I do not see why. I appreciate the time taken to look at the code I know there is a lot.

    Name_Sort:
    Option Explicit
    
    Sub Macro1()
    
    'Insert Blank Row Between Names
        Sheets("Sheet1").Select
        
        Range("A1").Select
        Do Until ActiveCell.Value = ""
            If ActiveCell.Value <> ActiveCell.Offset(1).Value Then
                ActiveCell.Offset(1).EntireRow.Insert
                ActiveCell.Offset(1).Select
            End If
            ActiveCell.Offset(1).Select
         Loop
        'End
        
    End Sub
    
    Sub Macro2()
    
        Dim LastRow As Long
        
        'Delete Inserted Rows
        Sheets("Sheet1").Select
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
        Range("A" & LastRow).Select
        Do Until ActiveCell.Value = Range("A1")
            If ActiveCell.Value <> ActiveCell.Offset(-1).Value Then
                ActiveCell.Offset(-1).EntireRow.Delete Shift:=xlUp
                ActiveCell.Offset(-1).Select
            End If
            ActiveCell.Offset(-1).Select
         Loop
        'End
    End Sub
    Copy of Resource Allocation:
    Sub Schedule_Resource()
    
        Dim LastRow As Long
        Dim CopyRange As String
        
    '    Application.ScreenUpdating = False
        
    '---------- ---------- Section 1 ---------- ----------
    'Copy from Temp to Stored Sheets, Sort, and Insert spacer rows
    
        'Copy
        Sheets("Temp_Data").Select
        Range("A1:D1").Select
        Selection.Copy
        
        'Paste to Employee_Data Sheet
    
        Sheets("Employee_Data").Select
        
        LastRow = Cells(Rows.Count, "B").End(xlUp).Row
        Range("B" & LastRow + 1).Select
      
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            
        'Sort
        Sheets("Employee_Data").Select
        LastRow = Cells(Rows.Count, "B").End(xlUp).Row
        
        Let CopyRange = "A" & LastRow & ":" & "E2"
        
        Range(CopyRange).Select
        
        Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
        'End
        
        'Insert Blank Row Between Names on Employee_Data Sheet
        Sheets("Employee_Data").Select
        
        Range("B2").Select
        Do Until ActiveCell.Value = ""
            If ActiveCell.Value <> ActiveCell.Offset(1).Value Then
                ActiveCell.Offset(1).EntireRow.Insert
                ActiveCell.Offset(1).Select
            End If
            ActiveCell.Offset(1).Select
         Loop
    
        'End
        
        'Copy
    
        Sheets("Temp_Data").Select
        Range("A1:D1").Select
        Selection.Copy
        
        'Paste to Project_Data Sheet
        Sheets("Project_Data").Select
        
        LastRow = Cells(Rows.Count, "B").End(xlUp).Row
        Range("B" & LastRow + 1).Select
      
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    
        'Sort
        Sheets("Employee_Data").Select
        LastRow = Cells(Rows.Count, "B").End(xlUp).Row
        
        Let CopyRange = "A" & LastRow & ":" & "E2"
        
        Range(CopyRange).Select
        
        Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
        'End
        'Insert Blank Row Between Names on Project_Data Sheet
        Sheets("Employee_Data").Select
        
        Range("B2").Select
        Do Until ActiveCell.Value = ""
            If ActiveCell.Value <> ActiveCell.Offset(1).Value Then
                ActiveCell.Offset(1).EntireRow.Insert
                ActiveCell.Offset(1).Select
            End If
            ActiveCell.Offset(1).Select
         Loop
    
        'End
       
    '--------- ---------- End Section 1 ---------- ----------
    
    
    '---------- ---------- Section 2 ---------- ----------
    'Copy from Data Sheets and paste on Dashboards and hide columns
        
    'Employee Sheet
        Sheets("Employee_Dashboard").Select
        Columns("C:D").Select
        Selection.EntireColumn.Hidden = False
        
        Columns("B:D").Select
        Selection.ClearContents
        
        Sheets("Employee_Data").Select
        LastRow = Cells(Rows.Count, "B").End(xlUp).Row
    
        Let CopyRange = "G" & LastRow & ":" & "I2"
        
        Range(CopyRange).Select
        Selection.Copy
            
        Sheets("Employee_Dashboard").Select
        Range("B4").Select
        
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
        Cells.Select
        Cells.EntireColumn.AutoFit
    
        Columns("C:D").Select
        Selection.EntireColumn.Hidden = True
        
        'Delete Inserted Rows
        Sheets("Employee_Data").Select
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
        Range("A" & LastRow).Select
        Do Until ActiveCell.Value = Range("A1")
            If ActiveCell.Value <> ActiveCell.Offset(-1).Value Then
                ActiveCell.Offset(-1).EntireRow.Delete Shift:=xlUp
                ActiveCell.Offset(-1).Select
            End If
            ActiveCell.Offset(-1).Select
         Loop
        'End
        
        'Project Sheet
        Sheets("Project_Dashboard").Select
        Columns("C:D").Select
        Selection.EntireColumn.Hidden = False
        
        Columns("B:D").Select
        Selection.ClearContents
        
        Sheets("Project_Data").Select
        LastRow = Cells(Rows.Count, "B").End(xlUp).Row
    
        Let CopyRange = "G" & LastRow & ":" & "I2"
        
        Range(CopyRange).Select
        Selection.Copy
            
        Sheets("Project_Dashboard").Select
        Range("B4").Select
        
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
        Cells.Select
        Cells.EntireColumn.AutoFit
    
        Columns("C:D").Select
        Selection.EntireColumn.Hidden = True
        
        'Delete Inserted Rows
        Sheets("Project_Data").Select
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
        Range("A" & LastRow).Select
        Do Until ActiveCell.Value = Range("A1")
            If ActiveCell.Value <> ActiveCell.Offset(-1).Value Then
                ActiveCell.Offset(-1).EntireRow.Delete Shift:=xlUp
                ActiveCell.Offset(-1).Select
            End If
            ActiveCell.Offset(-1).Select
         Loop
        'End
        
    '---------- ---------- End Section 2 ---------- ----------
    
    'Display Confirmation Number.
        Sheets("Form").Select
        Range("C3,C5,C7,C9").Clear
        MsgBox ("Scheduled!")
    'End
    
    'Save
        Sheets("Employee_Dashboard").Select
        Range("A1").Select
        ActiveWorkbook.Save
        Application.ScreenUpdating = True
    
    End Sub
    Last edited by am_hawk; 10-21-2013 at 02:20 PM. Reason: add attachments

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy Paste the Missing Values in a Specified Cells and Insert the Rows into a Report
    By judeprem in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2013, 01:46 PM
  2. Macro to Copy Values, Insert Row, Paste in Another, Delete Original Data
    By JimPDX in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-23-2013, 05:35 AM
  3. Excel Macro to insert two rows based on condition and copy and paste multiple cells
    By mannabhalo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-13-2012, 12:56 PM
  4. [SOLVED] Copy, paste and insert new rows into new sheets
    By nanas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-10-2012, 10:35 PM
  5. Copy and paste insert rows with protected cells in protected worksheet
    By excel_gecko in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-24-2012, 05:50 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