Hi everyone,
I'm stuck here, trying to write a macro that would filter data out of active worksheet and extract it into a new workbook. Please view attached file for reference.
I need the macro to filter the data in Activesheet (which would be protected except for column C) and extract each row in which there's a record of items being sold (C<>B; D>0; F>0). The data in column C would be entered manually.
Also it would be nice if at the same time the macro could copy entire column C and paste it into column B on sheet Stock (which would be hidden) so that the Items Left would represent new amounts of Items in stock. Anyway. this second feature is not of a top priority
Thank you for your time, friends.
I don't follow, what data are you trying to extract?
If you are happy with the answer, please click the Star icon in the below left hand corner.
Good sites to start learning.
snb's VBA Help Files
Jerry Beaucaires Excel Assistant
J & R Excel Consultancy Services
How to post code correctly: Correct Code Posting
All of those rows from Activesheet in which there's a record in column C (and C does not equal B) i.e. I need a list of all items that were sold.
You can use autofilter or advancedfilter.
You can use either method in a macro, so the user only has to click a button etc.
Easy enough, mate![]()
Not exactly sure this is what you are after, but here is the code anyway.
Code:
CheersDim ws As Worksheet Dim LR As Long Dim ws1 As Worksheet Dim i As Long Dim Wk As Workbook Dim j As Long Application.ScreenUpdating = False Set ws = Worksheets("Activesheet") Set ws1 = Worksheets("Stock") Set Wk1 = Workbooks.Add() LR = ws.Cells(ws.Rows.Count, 2).End(xlUp).Row j = 2 For i = 2 To LR If ws.Range("C" & i).Value <> "" Then Wk1.Worksheets("Sheet1").Range("A" & j).Resize(, 7).Value = ws.Range("A" & i).Resize(, 7).Value j = j + 1 End If Next i With Wk1 .Worksheets("Sheet1").Range("A1:G1") = ws.Range("A1:G1").Value .Worksheets("Sheet1").Range("A1:G1").EntireColumn.AutoFit End With Wk1.Worksheets("Sheet1").Range("A1:G1").Select With Selection.Borders .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 13434879 .TintAndShade = 0 .PatternTintAndShade = 0 End With ws1.Visible = True ws1.Range("B2:B" & LR).Value = ws.Range("C2:C" & LR).Value ws1.Visible = False Wk1.SaveAs "C:\Users\Owner\Desktop\YourFileName.xlsx", FileFormat:=51 Application.ScreenUpdating = True End Sub
If you are happy with the answer, please click the Star icon in the below left hand corner.
Good sites to start learning.
snb's VBA Help Files
Jerry Beaucaires Excel Assistant
J & R Excel Consultancy Services
How to post code correctly: Correct Code Posting
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks