I am a bit stuck: I have the below code for a spreadsheet which copies rows, selected with a checkbox, into a second sheet.
I now need to amend this code so that the copied rows are pasted into another workbook on a specific sheet.
I have tried Workbooks("").Worksheets("") and also using the whole C drive path but always get a run-time 9, subscript out of range error. I haven't had any luck in finding a solution online.
Both workbooks are saved on my desktop currently for ease:
Sub CopyRows()
For Each chkbx In ActiveSheet.CheckBoxes
If chkbx.Value = 1 Then
For r = 1 To Rows.Count
If Cells(r, 1).Top = chkbx.Top Then
With Worksheets("Sheet2")
LRow = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Range("A" & LRow & ":R" & LRow) = _
Worksheets("Sheet1").Range("A" & r & ":R" & r).Value
End With
Exit For
End If
Next r
End If
Next
End Sub
This recorded macro takes the data to where it needs to go:
Sub Transfer()
'
' Transfer Macro
'
'
Range("K2").Select
Selection.Copy
Windows("Destination.xls").Activate
Range("E7:E8").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
Range("B2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Destination.xls").Activate
Range("E9").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
Range("M2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Destination.xls").Activate
Range("E10").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
Range("G2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Destination.xls").Activate
Range("E11").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
Range("N2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Destination.xls").Activate
Range("E12").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
Range("E2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Destination.xls").Activate
Range("E13").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
Range("A2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Destination.xls").Activate
Range("E14").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
Range("S2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Destination.xls").Activate
Range("E15").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
Range("J2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Destination.xls").Activate
Range("E16").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
Range("I2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Destination.xls").Activate
Range("E17").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
Range("C2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Destination.xls").Activate
Range("E20").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
Range("D2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Destination.xls").Activate
Range("E21").Select
ActiveSheet.Paste
Windows("WIP - Live.xlsm").Activate
End Sub
Code with error at destination workbook:
Sub CopyRows()
For Each chkbx In ActiveSheet.CheckBoxes
If chkbx.Value = 1 Then
For r = 1 To Rows.Count
If Cells(r, 1).Top = chkbx.Top Then
With Workbooks("Destination").Sheets("Sheet2")
LRow = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Range("A" & LRow & ":R" & LRow) = _
Worksheets("Sheet1").Range("A" & r & ":R" & r).Value
End With
Exit For
End If
Next r
End If
Next
End Sub
Solved: I have managed to get it working with the below code:
Sub CopyRows()
For Each chkbx In ActiveSheet.CheckBoxes
If chkbx.Value = 1 Then
For r = 1 To Rows.Count
If Cells(r, 1).Top = chkbx.Top Then
With Workbooks("Destination.xlsm").Sheets("Details")
LRow = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Range("A" & LRow & ":U" & LRow) = _
Worksheets("Sheet2").Range("A" & r & ":U" & r).Value
End With
Exit For
End If
Next r
End If
Next
End Sub
The error was being caused by the Sheet 2 name in the destination workbook. I had to amend the name to details and it started working. Frustratingly simple for how long I spent on it!
Many Thanks to ed2 and norie for the replies and help. It is much appreciated.
Try this:
First:
Change
Worksheets("Sheet1").Range("A" & r & ":R" & r).Value
to
Workbooks("WIP - Live.xlsm").Sheets("Sheet1").Range("A" & r & ":R" & r).Value
Then:
Change
With Worksheets("Sheet2")
to
Workbooks("Destination.xls").Sheets("Sheet2")
This assumes that both workbooks are already open when the macro is run. If not, you will need code to open one or both of them.
Related
Dummy data of a tournament
Above is the example of the dummy data. My goal is to use VBA to group the data so that there is only one name displayed and the 3 Games populated with the Results so there would only be one line for the name as well as the 3 Games' results in the same line.
Example of the output data
Well, this is not as easy as first appears, however, this works:
So, the country is returned with classic index & match. The results are built by finding the result against each player and round. This expects blanks in the other cells for each player.
Try this:
Sub mSummarise()
'
' Macro1 Macro
'
'
Dim lData, lSummary, lFilter As String
Dim lRow1, lRow2, lRow3, lCol1, lCount As Long
lData = ActiveSheet.Name
Range("A1").Select
Selection.End(xlToRight).Select
lCol1 = ActiveCell.Column
Range("A1").Select
Selection.End(xlDown).Select
lRow1 = ActiveCell.Row
Sheets.Add After:=ActiveSheet
ActiveSheet.Name = "Summary"
Sheets(lData).Activate
Range("A1:B" & lRow1).Select
Selection.Copy
Sheets("Summary").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Range("$A$1:$B$" & lRow1).RemoveDuplicates Columns:=Array(1, 2), Header _
:=xlNo
Range("A1").Select
Selection.End(xlDown).Select
lRow2 = ActiveCell.Row
Sheets(lData).Select
Range(Cells(1, 3), Cells(1, lCol1)).Select
Selection.Copy
Sheets("Summary").Select
Range("C1").Select
ActiveSheet.Paste
Sheets(lData).Select
For lCount = 3 To lCol1
Range(Cells(1, 1), Cells(lRow1, lCol1)).Select
Selection.AutoFilter
ActiveSheet.Range(Cells(1, 1), Cells(lRow1, lCol1)).AutoFilter Field:=lCount, Criteria1:="<>", Operator:=xlAnd
Range(Cells(1, 1), Cells(lRow1, lCount)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets.Add After:=ActiveSheet
lFilter = ActiveSheet.Name
ActiveSheet.Paste
Range("A1").Select
Selection.End(xlDown).Select
lRow3 = ActiveCell.Row
Sheets("Summary").Select
Application.CutCopyMode = False
Cells(2, lCount).Select
ActiveCell.Formula = "=VLOOKUP(A2," & lFilter & "!$A$2:" & Cells(lRow3, lCount).Address & "," & lCount & ",0)"
Range(Cells(2, lCount), Cells(2, lCount)).Copy
Range(Cells(2, lCount), Cells(lRow3, lCount)).Select
ActiveSheet.Paste
Range(Cells(2, lCount), Cells(lRow3, lCount)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets(lFilter).Select
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
Sheets(lData).Select
Next
Selection.AutoFilter
Range("A1").Select
Sheets("Summary").Select
Range("A1").Select
End Sub
I'm a beginner in VBA and i have done a script which would call different macros according to the sheet name which is assigned to a variable SheetName. I'm trying to execute the below code and I'm getting a Compile Error. Hope you guys can help me!!
Sub ScrubeCareOutput()
Dim SheetName, Header, PolicyNumber As String
Dim CheckPoint As Integer
StartTime = Now()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets("ConsolidatedData").Select
Range("P:P").Cut
Range("A1").Select
ActiveCell.EntireColumn.Insert
Range("A1").Select
'Deleting old sheet
Application.StatusBar = "Calculating Loop .."
Sheets("Reference").Select
Range("L2").Select
ActiveCell.Offset(1, 0).Select
SheetName = ActiveCell.Value
'Scrubbing Output
Do Until SheetName = ""
Application.StatusBar = "Scrubbing " & SheetName & " Output.."
Sheets(SheetName).Select
Range("a1").Select
If IsEmpty(Range("A2")) = False Then
Range("A2").Select
Header = ActiveCell.Value
End If
'Deleting Headers
Selection.AutoFilter Field:=1, Criteria1:=Header
ActiveSheet.AutoFilter.Range.Offset(1, 0).Rows.SpecialCells(xlCellTypeVisible).Delete (xlShiftUp)
ActiveSheet.AutoFilterMode = False
Selection.AutoFilter Field:=1, Criteria1:=""
ActiveSheet.AutoFilter.Range.Offset(1, 0).Rows.SpecialCells(xlCellTypeVisible).Delete (xlShiftUp)
ActiveSheet.AutoFilterMode = False
Selection.AutoFilter Field:=1, Criteria1:="©Copyright Nebo Systems, Inc."
ActiveSheet.AutoFilter.Range.Offset(1, 0).Rows.SpecialCells(xlCellTypeVisible).Delete (xlShiftUp)
ActiveSheet.AutoFilterMode = False
Selection.AutoFilter Field:=1, Criteria1:="Powered by ECARE?"
ActiveSheet.AutoFilter.Range.Offset(1, 0).Rows.SpecialCells(xlCellTypeVisible).Delete (xlShiftUp)
ActiveSheet.AutoFilterMode = False
Range("1:1").Delete
'Scrubbing Data
Call SheetName
'Creating fields
For i = 1 To 4
ActiveCell.EntireColumn.Insert
Next
Range("A1").Select
ActiveCell.Value = "Account Number"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Mnemonic"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Begin Date"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "End Date"
'Formulating data
ActiveCell.Offset(1, -3).Select
ActiveCell.Value = "=VLOOKUP(E2,ConsolidatedData!$A:$S,3,0)"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "=VLOOKUP(E2,ConsolidatedData!$A:$S,16,0)"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "=VLOOKUP(E2,ConsolidatedData!$A:$S,17,0)"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "=VLOOKUP(E2,ConsolidatedData!$A:$S,18,0)"
ActiveCell.Offset(0, 1).Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, -4).Select
Range(Selection, Selection.End(xlUp)).Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.FillDown
Selection.Copy
Selection.PasteSpecial xlPasteValues
Range("a1").Select
'Formatting data
Application.StatusBar = "Formatting " & SheetName & " Output.."
With ActiveSheet
.Cells.Font.Name = "Calibri"
.Cells.Font.Size = "10"
End With
Range("1:1").Select
Selection.Font.Bold = True
Range("A1").Select
'Save data
ActiveWorkbook.Saved = True
Sheets("Reference").Select
ActiveCell.Offset(1, 0).Select
SheetName = ActiveCell.Value
Else
Sheets("Reference").Select
ActiveCell.Offset(1, 0).Select
SheetName = ActiveCell.Value
End If
Loop
Sheets("UB92Monitor").Select
'Confirmation message
ActiveWorkbook.Save
EndTime = Format((Now() - StartTime), "HH:MM:SS")
Application.StatusBar = False
MsgBox "Data scrubbed successfully in " & EndTime, vbOKOnly, "Data Scrubbing Status"
End Sub
I want to repeat this command in subsequent rows every 15th time.So the next one will be J348:M348
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("J318").Select
ActiveCell.FormulaR1C1 = "=R303C10-((R3C2-R4C2)/(R5C2/R6C2))"
Range("K318").Select
ActiveCell.FormulaR1C1 = "=R303C11-((R3C3-R4C3)/(R5C2/R6C2))"
Range("L318").Select
ActiveCell.FormulaR1C1 = "=RC[-5]"
Range("M318").Select
ActiveCell.FormulaR1C1 = "=RC[-5]"
Range("J318:M318").Select
Selection.AutoFill Destination:=Range("J318:M332"), Type:=xlFillDefault
Range("J318:M332").Select
ActiveWindow.SmallScroll Down:=0
Range("J332").Select
ActiveWindow.SmallScroll Down:=15
Range("J333:M333").Select
Selection.Copy
Range("J334").Select
ActiveSheet.Paste
Range("J335").Select
Application.CutCopyMode = False
Selection.Copy
Range("J334:M334").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
For a straight migration of your code to a looped code:
I randomly started at row 5 and used a do while loop. You could just as easily use a for loop. Hopefully this gives you the idea of the looping so you don't have to do it manually.
Public Sub Every15thRow()
Dim i As Integer
Dim iFirst, iSecond, iThird, iFourth, iFifth As Integer
'in Ex: 318, 303, 332, 333, 334
Dim MyStopCriteria As Boolean
MyStopCriteria = False
'... whatever your code does before
'...
i = 5 'start with the 5th row
Do Until MyStopCriteria = True
iFirst = i + 15
iSecond = i
iThird = i + 29
iFourth = i + 30
iFifth = i + 31
Application.CutCopyMode = False
Range("J" & iFirst).Select
ActiveCell.FormulaR1C1 = "=R" & iSecond & "C10-((R3C2-R4C2)/(R5C2/R6C2))"
Range("K" & iFirst).Select
ActiveCell.FormulaR1C1 = "=R" & iSecond & "C11-((R3C3-R4C3)/(R5C2/R6C2))"
Range("L" & iFirst).Select
ActiveCell.FormulaR1C1 = "=RC[-5]"
Range("M" & iFirst).Select
ActiveCell.FormulaR1C1 = "=RC[-5]"
Range("J" & iFirst & ":M" & iFirst).Select
Selection.AutoFill Destination:=Range("J" & iFirst & ":M" & iThird), Type:=xlFillDefault
Range("J" & iFirst & ":M" & iFourth).Select
ActiveWindow.SmallScroll Down:=0
Range("J" & iThird).Select
ActiveWindow.SmallScroll Down:=15
Range("J" & iThird & ":M" & iThird).Select
Selection.Copy
Range("J" & iFourth).Select
ActiveSheet.Paste
Range("J" & iFourth).Select
Application.CutCopyMode = False
Selection.Copy
Range("J" & iFifth & ":M" & iFifth).Select
'...
'... whatever else your repeating code needs to do
'...
i = i + 15 'Add 15 rows
If i > 40 Then MyStopCriteria = True
Loop
'... whatever else your code does after repeating
End Sub
I am a bit new to the macro's in excel and I am trying to find a way to adjust one of the macros I currently have in an excel file. I have a calculation that takes the columns D and E then subtracts D from E and adds it to the value of column B. here is the current code and also the sheet being used.
Sub InvAdj()
'
' InvAdj Macro
'
' Keyboard Shortcut: Ctrl+Shift+I
'
Columns("C:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("C1").Select
ActiveCell.FormulaR1C1 = "Quality"
Range("C2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]-RC[2]+RC[3]"
Range("C2").Select
Selection.AutoFill Destination:=Range("C2:C33")
Range("C2:C33").Select
Columns("C:C").Select
Selection.Copy
Columns("B:B").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Columns("C:C").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("D2:E33").Select
Selection.ClearContents
Range("F1").Select
End Sub
Not sure if this is what you are trying?
Sub InvAdj()
Dim ws As Worksheet
'~~> Change this to the relevant sheet
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
.Range("B1").Value = "Quality"
For i = 2 To 33
'~~> Check if all cells have data
If Len(Trim(.Range("B" & i).Value)) <> 0 And _
en(Trim(.Range("D" & i).Value)) <> 0 And _
en(Trim(.Range("E" & i).Value)) <> 0 Then
'B = B + (E - D)
.Range("B" & i).Value = .Range("B" & i).Value + _
(.Range("E" & i).Value - .Range("D" & i).Value)
End If
Next i
End With
End Sub
I have following data
ID Balance Balance_Sum Max_Balance
1 1000 2300 1500
1 -200 2300 1500
1 1500 2300 1500
My next column will Calculate some value if(Max_Balance < Balance_sum).
If this calculated value is > 0 then I have to select the next maximum value i.e 1000.
How can I achieve this using formula. Calculations shown above are for 1 ID. I may have thousands of such ID group.
I can not use VBA cause my file size will get too large and it takes time to load.
I guess what you need is a part of a formula that computes a =MAX(...) "from here to the end of the list". This can be done using the =OFFSET(...) function. Let's have our list of values starting from A1, and the relative MAX starting at B1
B1: =MAX(OFFSET(A1;0;0;COUNT(A1:A$1000)))
whereby the last term of COUNT() is so high that it makes sure all rows are included. This works only as long as there are no blank rows in between.
You can copy this formula down and across, row 1000 is the only invariant here.
Sub abc()
j = 2
ActiveSheet.Range("a1").Select
ActiveSheet.Range("a65536").Select
lastrow = Selection.End(xlUp).Row
ActiveSheet.Range("a1").Select
For i = 2 To lastrow
Range("a" & i).Select
If Range("a" & i).Value = "East" Or Range("a" & i).Value = "west" Or Range("a" & i).Value = "north" Or _
Range("a" & i).Value = "south" Then
GoTo cont
Else
Rows(i).Select
Application.CutCopyMode = False
Selection.Cut
Sheets("Sheet2").Select
Range("a" & j).Select
ActiveSheet.Paste
j = j + 1
Sheets("sheet1").Select
Selection.Delete Shift:=xlUp
End If
cont:
Next i
'/////// column b ///////////
ActiveSheet.Range("a1").Select
For i = 2 To lastrow
Range("b" & i).Select
If Range("b" & i).Value >= "01-01-2013" And Range("b" & i).Value <= "30-06-2013" Then
GoTo cont2
Else
Rows(i).Select
Application.CutCopyMode = False
Selection.Cut
Sheets("Sheet2").Select
Range("a" & j).Select
ActiveSheet.Paste
j = j + 1
Sheets("sheet1").Select
Selection.Delete Shift:=xlUp
End If
cont2:
Next i
End Sub
Sub abc()
j = 2
Sheets("sheet1").Select
ActiveSheet.Range("a1").Select
ActiveSheet.Range("a65536").Select
lastrow = Selection.End(xlUp).Row
'/// column a
ActiveSheet.Range("a3:a" & lastrow).Select
Selection.AutoFilter
ActiveSheet.Range("$A$4:$A$" & lastrow).AutoFilter Field:=1, Criteria1:="="
Application.CutCopyMode = False
Selection.EntireRow.Select
' Range(Selection, Selection.End(xlToRight)).Select
rownum = Selection.Row
If rownum = 3 Then
Selection.AutoFilter
GoTo label1
End If
Selection.Copy
Sheets("Sheet2").Select
'lrow = ActiveSheet.Range("A65536").End(xlUp).Row
lrow = Cells.Find(what:="*", after:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
ActiveSheet.Range("a" & lrow + 1).Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Application.CutCopyMode = False
Selection.EntireRow.Delete
Selection.AutoFilter
'column b///////////
label1:
ActiveSheet.Range("b65536").Select
lastrow = Selection.End(xlUp).Row
ActiveSheet.Range("b4:b" & lastrow).Select
Selection.AutoFilter
ActiveSheet.Range("$b$1:$b$" & lastrow).AutoFilter Field:=1, Criteria1:="="
Application.CutCopyMode = False
Range(Selection, Selection.End(xlToLeft)).Select
Selection.EntireRow.Select
'Range(Selection, Selection.End(xlToRight)).Select
rownum = Selection.Row
If rownum = 3 Then
Selection.AutoFilter
GoTo label2
End If
Selection.Copy
Sheets("Sheet2").Select
'lrow = ActiveSheet.Range("A65536").End(xlUp).Row
lrow = Cells.Find(what:="*", after:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
ActiveSheet.Range("a" & lrow + 1).Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Application.CutCopyMode = False
Selection.EntireRow.Delete
' Selection.AutoFilter
'column c////////////
label2:
ActiveSheet.Range("c65536").Select
lastrow = Selection.End(xlUp).Row
ActiveSheet.Range("c4:c" & lastrow).Select
Selection.AutoFilter
ActiveSheet.Range("$c$1:$c$" & lastrow).AutoFilter Field:=1, Criteria1:="SG Plus", _
Operator:=xlOr, Criteria2:="=Select"
Application.CutCopyMode = False
'Range(Selection, Selection.End(xlToRight)).Select
' Selection.Copy
' Sheets("Sheet2").Select
' lrow = activehseet.Range("A65536").End(xlUp).Row
' ActiveSheet.Range("a" & lrow).Select
' ActiveSheet.Paste
' Sheets("Sheet1").Select
rownum = Selection.Row
If rownum = 3 Then
Selection.AutoFilter
GoTo label3
End If
Range("a4:a" & lastrow).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.EntireRow.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Application.CutCopyMode = False
Selection.EntireRow.Delete
' Selection.AutoFilter
'column c again/////////////
label3:
ActiveSheet.Range("c65536").Select
lastrow = Selection.End(xlUp).Row
ActiveSheet.Range("c4:c" & lastrow).Select
Selection.AutoFilter
ActiveSheet.Range("$c$1:$c$" & lastrow).AutoFilter Field:=1, Criteria1:="="
Application.CutCopyMode = False
rownum = Selection.Row
If rownum = 3 Then
Selection.AutoFilter
GoTo label4
End If
Range(Selection, Selection.End(xlToRight)).Select
Range("a4:a" & lastrow).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.EntireRow.Copy
Sheets("Sheet2").Select
'lrow = ActiveSheet.Range("A65536").End(xlUp).Row
lrow = Cells.Find(what:="*", after:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
ActiveSheet.Range("a" & lrow + 1).Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Application.CutCopyMode = False
Selection.EntireRow.Delete
' Selection.AutoFilter
'////////////////////////// over /////////////////////////////
label4:
ActiveSheet.Range("a1").Select
For i = 4 To lastrow
Range("a" & i).Select
If Range("a" & i).Value = "MidAmerica" Or Range("a" & i).Value = "Northeast" Or Range("a" & i).Value = "Southeast" Or _
Range("a" & i).Value = "West" Then
GoTo cont
Else
Rows(i).Select
Application.CutCopyMode = False
Selection.Cut
Sheets("Sheet2").Select
lrow = Cells.Find(what:="*", after:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
Range("a" & lrow + 1).Select
ActiveSheet.Paste
j = j + 1
Sheets("sheet1").Select
Selection.Delete Shift:=xlUp
End If
cont:
Next i
'/////// column b ///////////
ActiveSheet.Range("a1").Select
For i = 4 To lastrow
Range("b" & i).Select
If Range("b" & i).Value = "CA" Or Range("b" & i).Value = "AZ" Then
GoTo cont2
Else
Rows(i).Select
Application.CutCopyMode = False
Selection.Cut
Sheets("Sheet2").Select
lrow = Cells.Find(what:="*", after:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
Range("a" & lrow + 1).Select
ActiveSheet.Paste
j = j + 1
Sheets("sheet1").Select
Selection.Delete Shift:=xlUp
End If
cont2:
Next i
'///////////column c //////////
ActiveSheet.Range("a1").Select
For i = 4 To lastrow
Range("c" & i).Select
If Range("c" & i).Value = "SG" Then
GoTo cont3
Else
Rows(i).Select
Application.CutCopyMode = False
Selection.Cut
Sheets("Sheet2").Select
lrow = Cells.Find(what:="*", after:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
Range("a" & lrow + 1).Select
ActiveSheet.Paste
j = j + 1
Sheets("sheet1").Select
Selection.Delete Shift:=xlUp
End If
cont3:
Next i
'//////////column l/////////////
ActiveSheet.Range("a1").Select
For i = 4 To lastrow
Range("l" & i).Select
If Range("l" & i).Value <= "01/06/2014" And Range("l" & i).Value >= "01/01/2013" Then
GoTo cont4
Else
Rows(i).Select
Application.CutCopyMode = False
Selection.Cut
Sheets("Sheet2").Select
lrow = Cells.Find(what:="*", after:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
Range("a" & lrow + 1).Select
ActiveSheet.Paste
j = j + 1
Sheets("sheet1").Select
Selection.Delete Shift:=xlUp
End If
cont4:
Next i
'//////////column m/////////////
ActiveSheet.Range("a1").Select
For i = 4 To lastrow
Range("m" & i).Select
If Range("m" & i).Value = "12/01" Or Range("m" & i).Value = "12/05" Then
GoTo cont5
Else
Rows(i).Select
Application.CutCopyMode = False
Selection.Cut
Sheets("Sheet2").Select
lrow = Cells.Find(what:="*", after:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
Range("a" & lrow + 1).Select
ActiveSheet.Paste
j = j + 1
Sheets("sheet1").Select
Selection.Delete Shift:=xlUp
End If
cont5:
Next i
'//////////column q and r/////////////
ActiveSheet.Range("a1").Select
For i = 4 To lastrow
Range("q" & i).Select
If Range("q" & i).Value <> " " And Range("r" & i).Value <> " " And Range("u" & i).Value <> " " _
And Range("z" & i).Value <> " " And Range("aa" & i).Value <> " " And Range("ab" & i).Value <> " " _
And Range("b" & i).Value <> " " And Range("j" & i).Value <> " " Then
GoTo cont6
Else
Rows(i).Select
Application.CutCopyMode = False
Selection.Cut
Sheets("Sheet2").Select
lrow = Cells.Find(what:="*", after:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
Range("a" & lrow + 1).Select
ActiveSheet.Paste
j = j + 1
Sheets("sheet1").Select
Selection.Delete Shift:=xlUp
End If
cont6:
Next i
End Sub