editing filter formulae

patni

Board Regular
Joined
Jul 22, 2018
Messages
58
Hey Guys,

I need help.

This question is however cross posted .
here is the link :


https://www.excelforum.com/excel-pr...-filter-modifying-formulae-2.html#post4942600

I have this code to filter sheet "PRODUCT" based on column "IN STOCK"
If cell matches "INSTOCK" then it is copied to sheet "stock in hand"

Now the problem is that the vba code clears the entire used range.
If it possible that to add an exception - to not clear upto row 6?

Because if i enter any data in row 1-6, then it autoclears it


Here is the vba code to edit

Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Private Sub Worksheet_Activate()
         Me.UsedRange.Clear
    With Worksheets("PRODUCT")
        .[Z1:Z2].Value = [{"stock in hand";"IN STOCK"}]
        .Cells(5, 1).ListObject.Range.AdvancedFilter xlFilterCopy, .[Z1:Z2], Cells(7,1)
        .[Z1:Z2].Clear
    End With
End Sub</code>


Please help me
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try:

Code:
Me.UsedRange.Offset(6).Clear

WBD


Hey Thanks for your promt reply.

This code does not clear data upto row 6, however it does not copy the entire row from sheet"PRODUCT"

It copies only range A of sheet "product"
It fails to copy the data typed in other cell.
 
Upvote 0
The original code copies the entire row.
The code modified by you copies only 1st column.
 
Upvote 0
Hey ,

Sure. Thanks.

but when i emplement the changes recommended , it fails to copy the entire row.

Is there any way ?
 
Upvote 0
I'm not 100% familiar with AdvancedFilter but perhaps having data in row 6 will prevent it from working. How about:

Code:
Private Sub Worksheet_Activate()
    Dim savedRows
    savedRows = Range("1:6").Value
    Me.UsedRange.Clear
    With Worksheets("PRODUCT")
        .[Z1:Z2].Value = [{"stock in hand";"IN STOCK"}]
        .Cells(5, 1).ListObject.Range.AdvancedFilter xlFilterCopy, .[Z1:Z2], Cells(7, 1)
        .[Z1:Z2].Clear
    End With
    Range("1:6").Value = savedRows
End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,290
Members
449,149
Latest member
mwdbActuary

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