VBA code to move data with selected criteria - coding questions

jnash

New Member
Joined
Nov 20, 2015
Messages
1
Hi,

I am trying to create some code that will move data from one worksheet to another if it meets a certain criteria.The criteria will be a product category and a week number. If possible the week number will change incrementally and on a weekly basis. For example this week is week number 37 when I run the code next week the 37 will increase to look for week 38. (I am using excel 2013)

So far I have been using auto filters and haven't had much luck, I have also used an if and copy code (posted below)

Auto filter code:

Code:
 ActiveSheet.Range("$A$2:$X$300").AutoFilter Field:=26, Criteria1:="Bath"
    ActiveSheet.Range("$A$2:$X$300").AutoFilter Field:=2, Criteria1:=“37”
 
 
Range("A2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
 
 
    Sheets("Bath Data").Select
   Range("A1").Select
   
ActiveSheet.Paste


If and copy code:

Code:
Dim i, LastRow
 
LastRow = Sheets("Units YTD").Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To LastRow
  
    If Sheets("Units YTD").Cells(i, "Z").Value = "Bath" Then ....

I also want the code to paste the new data below the previous data when it is pasted into the new sheet.

to achieve this I was using this code:

Code:
Sheets("Units YTD").Range("A" & i).Copy Destination:=Sheets("Bath Data").Range("A" & Rows.Count).End(xlUp).Offset(1)


Could the combination of the three parts of code I have pasted here be used to achieve the outcome I want ?

or is there a new code I could use ? (I am very new to VBA so I feel I could be missing something obvious)

Thanks in advance for your help, apologies if the format of my post does not follow the guidelines or it is confusing.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

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
Back
Top