I want to use autofill to automatically apply a formula.

SamuelSeawall

New Member
Joined
Oct 21, 2021
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Sub CopFilteredData2()
Dim rng As Range
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Transhipment - October 2021")

If ws.AutoFilterMode = False Then
ws.ListObjects("Inventory").Range.AutoFilter Field:=11, Criteria1:="On Terminal"
End If

Set rng = ws.ListObjects("Inventory").Range

rng.SpecialCells(xlCellTypeVisible).Copy 'Only the visible cells and not all of them

ws.ListObjects("Inventory").AutoFilter.ShowAllData 'This is intended to reset the filters on the 'Inventory' table

Dim wb As Workbook, NewWS As Worksheet
Set wb = Application.Workbooks.Add
Set NewWS = wb.Sheets(1)

ActiveWorkbook.Sheets("Sheet1").ListObjects.Add(xlSrcRange, Range("$A$1:$N$1"), , xlYes).Name = _
"Table2"
NewWS.Paste


Sheets.Add After:=NewWS
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A:$A"), , xlYes).Name = _
"Table1"
Columns("A:A").Select
ActiveWorkbook.Names.Add Name:="T_S_auto", RefersToR1C1:= _
"=Table1[[#All],[Column1]]"

Dim K As Range

Set K = Range("K2").End(xlDown)




NewWS.Range("K2").FormulaR1C1 = "=IF([@[Match ]]>0,""LOADED"", ""ON TERMINAL"")"
NewWS.Range("L2").FormulaR1C1 = "=IFERROR(MATCH([@VIN],T_S_auto,0),0)"
NewWS.Range("N2").FormulaR1C1 = "=IFERROR(DAYS([@[Dep. date]],[@ETA]),0)"





'=IF([@[Match ]]>0,"LOADED", "ON TERMINAL")
'=IFERROR(MATCH([@VIN],Loaded,0),0)
End Sub
 

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.
Welcome to the Board!

Here are two tips to help you improve your changes of receiving assistance:

1. Don't just post your code. Explain, in detail, exactly what it is that you are trying, references exact range addresses and parts of the code that need updating. Posting an image of your sheet may also be helpful to pople can see what you are working with.

2. Use Code Tags when posting code so that it is easier to follow. See: How to Post Your VBA Code
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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