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
Bookmarks