Jlopez21887
New Member
- Joined
- Oct 31, 2016
- Messages
- 8
I have macro that loops though a WS to find a value of Late in Column W. I copy that row to a new Sheet currently Called Destination Cells.
Currently when the word "Late" is found the action is to copy the entire row to the Destination sheet.
For this report I only need 6-8 Columns to be copied to the destination sheet instead of the entire row. Columns are D-G, R-T, W and AD
AS you can see my last step is to delete unneeded columns but that is becoming cumbersome as the sheet is quite large.
I need to copy only the select cells in that row and then paste to the Destination sheet.
The code part that needs editing is
Thank you for any help.
Currently when the word "Late" is found the action is to copy the entire row to the Destination sheet.
For this report I only need 6-8 Columns to be copied to the destination sheet instead of the entire row. Columns are D-G, R-T, W and AD
AS you can see my last step is to delete unneeded columns but that is becoming cumbersome as the sheet is quite large.
I need to copy only the select cells in that row and then paste to the Destination sheet.
The code part that needs editing is
Code:
"[COLOR=#574123]txt.EntireRow.Copy Worksheets("DestinationCells").Range("A" & rowValue)"
[/COLOR]
Thank you for any help.
Code:
Sub LateStatusReport()
Dim lastRow As Double
Dim rowValue As Integer
Dim txt As Range
Dim shname As String
Dim newWS As Worksheet ' eventually set up to create new sheet every time
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Worksheets("DestinationCells").Activate
Worksheets("DestinationCells").Range("A3:AJ50").Delete
DestinationCellRow = Range("A" & Rows.Count).End(xlUp).Row
[COLOR=#008000] ' Eventually move to deleting worksheet and recreating new every run
'Sheets("DestinationCells").Delete
' Set newWS = Sheets.Add(After:=Sheets(Worksheets.count))
'ActiveSheet.Name = "DestinationCells"[/COLOR]
[COLOR=#008000] 'Find if user input sheet exists[/COLOR]
Do Until WorksheetExists(shname)
shname = InputBox("Enter sheet name")
If Not WorksheetExists(shname) Then MsgBox shname & " doesn't exist!", vbExclamation
Loop
[COLOR=#008000]'select user input sheet and get last row[/COLOR]
Sheets(shname).Select
lastRow = Range("A" & Rows.Count).End(xlUp).Row
[COLOR=#008000]'copy header rows[/COLOR]
Worksheets(shname).Range("A1:AJ3").Copy _
Destination:=Worksheets("DestinationCells").Range("A1")
[COLOR=#008000]'set paste row to row 4 to avoid header[/COLOR]
rowValue = 4
[COLOR=#008000]
'find if the value "Late" in Column W, if yes paste data to new sheet[/COLOR]
For Each txt In Sheets(shname).Range("W2:W" & lastRow)
If txt.Value = "Late" Then
[COLOR=#008000] 'copy and paste to Destination sheet[/COLOR]
txt.EntireRow.Copy Worksheets("DestinationCells").Range("A" & rowValue)
rowValue = rowValue + 1
End If
Next txt
[COLOR=#008000] 'Delete Columns that are not needed[/COLOR]
Sheets("DestinationCells").Range("A:A,B:B,C:C,H:H,I:I,J:J,K:K,L:L,M:M,N:N,O:O,P:P,Q:Q,U:U,X:X,Y:Y,Z:Z,AA:AA,AB:AB,AC:AC").EntireColumn.Delete
Application.ScreenUpdating = True
Application.DisplayAlerts = True
ActiveWorkbook.Save
End Sub