vba, macro, shift down after autofilter

mawar5530

New Member
Joined
Apr 5, 2020
Messages
38
Office Version
  1. 2016
Platform
  1. Windows
  2. Mobile
Hi Friends,

I am new to vba, really need help to find solution.
After autofilter the selction of "Poitem" example, i want to change G coloumn number beloging to "Poitem" to "zero" value
i dont find any way to offset, because the range keep on changing acording to report, so the offset not working for me.

1586156618873.png
 

Attachments

  • Capture.PNG
    Capture.PNG
    28 KB · Views: 16
Why we specify G2, instead ? because if i filter like different field example"PurReq", then the formula not working right ?
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Why we specify G2, instead ? because if i filter like different field example"PurReq", then the formula not working right ?

'Range("H2:H" & Range("H" & Rows.Count).End(xlUp).Row).SpecialCells(12).Formula = "=IF(F2=0, ABS(F2-G2),F2-G2)"
 
Upvote 0
There is nothing wrong with the syntax you have posted, I can't tell what you mean by "PurReq" as I can't see by your image what headings go with what columns (I can't actually see a column called "PurReq" even).

If you need anymore help post your code in the thread (in code tags) and post a sample of your unfiltered data (about 20 rows) using the boards XL2BB addin, then explain what issue you have.
 
Upvote 0
Columns("H:H").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("A:AT").AutoFilter Field:=4, Criteria1:=Array( _
"POitem", "PurRqs", "ShpgNt"), Operator:=xlFilterValues
Range("F2:F" & Range("F" & Rows.Count).End(xlUp).Row).SpecialCells(12).Value = 0
Range("H3:H" & Range("H" & Rows.Count).End(xlUp).Row).SpecialCells(12).Formula = "=IF(F2=0, ABS(F2-G2),F2-G2)"
Selection.Copy
Selection.AutoFilter
 

Attachments

  • Capture.PNG
    Capture.PNG
    72.4 KB · Views: 0
Upvote 0
Columns("H:H").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("A:AT").AutoFilter Field:=4, Criteria1:=Array( _
"POitem", "PurRqs", "ShpgNt"), Operator:=xlFilterValues
Range("F2:F" & Range("F" & Rows.Count).End(xlUp).Row).SpecialCells(12).Value = 0
Range("H3:H" & Range("H" & Rows.Count).End(xlUp).Row).SpecialCells(12).Formula = "=IF(F2=0, ABS(F2-G2),F2-G2)"
Selection.Copy
Selection.AutoFilter

I try to acess to xl2bb, but something wrong in setup.
sucessfully install but i cant mr excel in ribon and also the addin not found but selected.
 

Attachments

  • Capture.PNG
    Capture.PNG
    72.4 KB · Views: 1
Upvote 0
First of all you need to use vba or Rich code tags when posting code, you have quoted in the previous post. Anyway...
You haven't got any data in column H so it can't find a last row using that column. Try...
VBA Code:
Range("H2:H" & Range("G" & Rows.Count).End(xlUp).Row).SpecialCells(12).Formula = "=IF(F2=0, ABS(F2-G2),F2-G2)"
 
Last edited:
Upvote 0
First of all you need to use vba or Rich code tags when posting code, you have quoted in the previous post. Anyway...
You haven't got any data in column H so it can't find a last row using that column. Try...
VBA Code:
Range("H2:H" & Range("H" & Rows.Count).End(xlUp).Row).SpecialCells(12).Formula = "=IF(F2=0, ABS(F2-G2),F2-G2)"

not working.
My problem is, after filter the range will run according to data list.
Therefore, cannot specify the range of.
Once filter, the formula need to paste according at column "H"
 

Attachments

  • Capture.PNG
    Capture.PNG
    151.7 KB · Views: 2
Upvote 0
That code that you posted is not what I posted in my last post, which was

Rich (BB code):
Range("H2:H" & Range("G" & Rows.Count).End(xlUp).Row).SpecialCells(12).Formula = "=IF(F2=0, ABS(F2-G2),F2-G2)"

Test it without altering it please.
 
Upvote 0
That code that you posted is not what I posted in my last post, which was

Rich (BB code):
Range("H2:H" & Range("G" & Rows.Count).End(xlUp).Row).SpecialCells(12).Formula = "=IF(F2=0, ABS(F2-G2),F2-G2)"

Test it without altering it please.

Superb!
Thank you, tq, tq....
Its work and very sorry.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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