LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default using filter based on last column

Hi

Look at this. I only changed it for FromWks.

Sub CADFixtureTable()
Dim FromWks As Worksheet
Dim ToWks As Worksheet
Dim RngToFilter As Range
Dim RngToCopy As Range
Dim LastCol As Long

Set FromWks = Worksheets("fixture counts")
Set ToWks = Worksheets("CAD Fixture Schedule")

ToWks.Range("A3:F500").ClearContents

With FromWks
.AutoFilterMode = False
LastCol = .Cells(14, Columns.Count).End(xlToLeft).Column
Set RngToFilter = .Range(.Cells(LastCol - 4), .Cells(.Rows.Count,
LastCol - 4).End(xlUp))
RngToFilter.AutoFilter Field:=1, Criteria1:="<"

If .AutoFilter.Range.Columns(1).Cells.SpecialCells
(xlCellTypeVisible) _
.Cells.Count = 1 Then

Else
With RngToFilter
Set RngToCopy = .Resize(.Rows.Count - 1, 6).Offset(1, -1)
End With
RngToCopy.Copy
ToWks.Range("a3").PasteSpecial Paste:=xlPasteValues
Sheets("Fixture Counts").Range("$AF$14:$AF$91").AutoFilter
Field:=1
'ToWks.Select
End If
End With
End Sub

Regards,
Per

On 30 Sep., 16:22, Scott wrote:
I currently have the code below which only looks at AF:14 to filter data. *I
would like to add/delete data... so I need the code to find the last column
with data and filter 4 cells left of that. * EX.. Currently AJ has last data
so needs to read AF:14 but if add 2 columns need to look at AM and filter
AH:14

Sub CADFixtureTable()

* * Dim FromWks As Worksheet
* * Dim ToWks As Worksheet
* * Dim RngToFilter As Range
* * Dim RngToCopy As Range

* * Set FromWks = Worksheets("fixture counts")
* * Set ToWks = Worksheets("CAD Fixture Schedule")

* * ToWks.Select
* * Range("A3:F500").Select
* * Selection.ClearContents

* * With FromWks
* * * * .AutoFilterMode = False

* * * * Set RngToFilter = .Range("AF14", .Cells(.Rows.Count, "AF").End(xlUp))
* * * * RngToFilter.AutoFilter Field:=1, Criteria1:="<"

* * * * If
.AutoFilter.Range.Columns(1).Cells.SpecialCells(xl CellTypeVisible) _
* * * * * .Cells.Count = 1 Then

* * * * Else
* * * * * * With RngToFilter

* * * * * * * * Set RngToCopy = .Resize(.Rows.Count - 1, 6).Offset(1, -1)
* * * * * * End With

* * * * * *RngToCopy.Copy
* * * * * *ToWks.Range("a3").PasteSpecial Paste:=xlPasteValues

* * * * Sheets("Fixture Counts").Select
* * * * ActiveSheet.Range("$AF$14:$AF$91").AutoFilter Field:=1

* * * * ToWks.Select
* * * * End If
* * End With

End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter duplicates based on criteria / column values phillr Excel Discussion (Misc queries) 0 April 9th 10 09:13 PM
filter or format based on criteria in more than one column tabbicat Excel Worksheet Functions 4 March 13th 07 02:24 PM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Programming 2 December 30th 06 06:23 PM
Filter based on a column of items Pasko1 Excel Discussion (Misc queries) 1 August 22nd 05 11:56 PM
chk box to filter or hide rows based on value in a column deanop Excel Programming 6 January 7th 05 02:27 AM


All times are GMT +1. The time now is 03:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"