steps are the same but the data amount is always different

Status
Not open for further replies.

Tonyk1051

New Member
Joined
Feb 1, 2021
Messages
33
Office Version
  1. 2019
Platform
  1. Windows
all the inserts and columns are always the same but once it gets to the filter part, the amount of data it pulls will always be different, next week there could a 3000 more lines or 3000 less
is there away to modify this code so that it can work with any amount of data? like i said steps are always the same search criteria is always the same


VBA Code:
Sub Macro1()

'

' Macro1 Macro

' step 1

'



'

Rows("1:1").Select

Selection.Delete Shift:=xlUp

Columns("H:H").Select

Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

ActiveWindow.LargeScroll ToRight:=2

ActiveWindow.SmallScroll ToRight:=-1

Columns("W:W").Select

Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

Sheets("On a Category").Select

Columns("H:H").Select

Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

ActiveWindow.LargeScroll ToRight:=2

Columns("W:W").Select

Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

ActiveWindow.ScrollColumn = 1

Cells.Select

Selection.AutoFilter

ActiveSheet.Range("$A$1:$AK$26589").AutoFilter Field:=7, Criteria1:=Array( _                           (i always uncheck the boxes and check the same 5, what ever is pulled is moved to sheet 1)

"MANUFACTURE", "PICTURE OF DEFECT DONE", "TESTED CONFIRMED DAMAGED", _

"TESTED CONFIRMED DEFECTIVE", "WORKING BUT MISSING PARTS"), Operator:= _

xlFilterValues

Rows("122:122").Select

Range(Selection, Selection.End(xlDown)).Select

Selection.Cut

Sheets("Not on a Category").Select

ActiveWindow.ScrollRow = 11655

ActiveWindow.ScrollColumn = 1

Range("A11678").Select

ActiveSheet.Paste

ActiveWindow.ScrollRow = 1

Cells.Select

Selection.AutoFilter

ActiveSheet.Range("$A$1:$AK$38140").AutoFilter Field:=12, Criteria1:=Array( _                      (in the filter box, i  search for anything that has tt and tv and delete what ever it pulls)

"TT-01-DC", "TT-03-A", "TT-03-DC", "TT-04-A", "TT-08-A", "TT-21-DD", "TT-23-A", _

"TT-24-A", "TT-24-B", "TT-24-DA", "TT-24-F", "TT-25-A", "TT-30-A", "TT-31-A", _

"TT-32-A", "TT-33-A", "TT-34-A", "TT-35-A", "TT-38-A", "TT-40-A", "TT-41-A", "TT-42-A" _

, "TT-43-A", "TT-45-A", "TT-46-A", "TT-47-A", "TT-48-A", "TT-49-A", "TT-50-A", _

"TT-52-A", "TT-53-A", "TT-55-A"), Operator:=xlFilterValues

Rows("2:2").Select

Range(Selection, Selection.End(xlDown)).Select

Selection.Delete Shift:=xlUp

ActiveSheet.Range("$A$1:$AK$36959").AutoFilter Field:=12, Criteria1:= _

"TV-01-A"

Rows("1665:1665").Select

Range(Selection, Selection.End(xlDown)).Select

Selection.Delete Shift:=xlUp

Cells.Select

Selection.AutoFilter

End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,239
It looks like your code can be simplified to make it more efficient. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,794
Office Version
  1. 365
Platform
  1. Windows
Duplicate to: in need of a macro for a complex task

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Status
Not open for further replies.

Watch MrExcel Video

Forum statistics

Threads
1,128,126
Messages
5,628,858
Members
416,345
Latest member
sayad

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top