Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Macro/VB coding question

I want a macro to work for a worksheet name which will always be the same
directory and file name but the data inside worksheet will periodically
change - increase in rows/decrease in rows. # of Columns/Column names will
not change. I'm trying to filter for a non-changing set of info, then delete
the results.

Here's what I get if I record my current run:

Workbooks.Open Filename:= _
"***Directory of location and file name here***"
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$S$746").AutoFilter Field:=5,
Criteria1:=Array("10" _
, "11", "12", "13"), Operator:=xlFilterValues
Rows("2:28").Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$1:$S$719").AutoFilter Field:=5
Rows("1:1").Select
Selection.AutoFilter

I see the ActiveSheet.Ranges will need to change with each incarnation of
the worksheet. So, I could probably set these to A1:S60000 as the
spreadsheet will never get beyond that many rows. But, selecting the results
of filter - rows to delete portion is problematic. Any suggestions? Or
should I filter and set the Operator to delete? If so, what would that look
like?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,522
Default Macro/VB coding question

If desired, send your file to my address below. I will only look if:
1. You send a copy of this message on an inserted sheet
2. You give me the newsgroup and the subject line
3. You send a clear explanation of what you want
4. You send before/after examples and expected results.


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"melExcel2007" wrote in message
...
I want a macro to work for a worksheet name which will always be the same
directory and file name but the data inside worksheet will periodically
change - increase in rows/decrease in rows. # of Columns/Column names
will
not change. I'm trying to filter for a non-changing set of info, then
delete
the results.

Here's what I get if I record my current run:

Workbooks.Open Filename:= _
"***Directory of location and file name here***"
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$S$746").AutoFilter Field:=5,
Criteria1:=Array("10" _
, "11", "12", "13"), Operator:=xlFilterValues
Rows("2:28").Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$1:$S$719").AutoFilter Field:=5
Rows("1:1").Select
Selection.AutoFilter

I see the ActiveSheet.Ranges will need to change with each incarnation of
the worksheet. So, I could probably set these to A1:S60000 as the
spreadsheet will never get beyond that many rows. But, selecting the
results
of filter - rows to delete portion is problematic. Any suggestions? Or
should I filter and set the Operator to delete? If so, what would that
look
like?


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Macro/VB coding question

Unfortunately, I cannot share the file - it's a work file.
I'm trying to code a "macro" in one worksheet to open a seperate worksheet
which will always be named the same and the # of columns will always be the
same, but the # of rows and the data in the rows will change. I need to
filter the separate worksheet, then delete what I've filtered. Then "find"
blank row-entries in specific columns and replace with 0's. 2nd Macro: Then
create a Pivot table (in same worksheet but on separate tab) - same table
format each time, but rows/info in seperate worksheet will change. Copy and
paste value that pivot into another seperate tab and modify it (add columns
and formulas). Then save the file as different name from original worksheet.

"Don Guillett" wrote:

If desired, send your file to my address below. I will only look if:
1. You send a copy of this message on an inserted sheet
2. You give me the newsgroup and the subject line
3. You send a clear explanation of what you want
4. You send before/after examples and expected results.


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"melExcel2007" wrote in message
...
I want a macro to work for a worksheet name which will always be the same
directory and file name but the data inside worksheet will periodically
change - increase in rows/decrease in rows. # of Columns/Column names
will
not change. I'm trying to filter for a non-changing set of info, then
delete
the results.

Here's what I get if I record my current run:

Workbooks.Open Filename:= _
"***Directory of location and file name here***"
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$S$746").AutoFilter Field:=5,
Criteria1:=Array("10" _
, "11", "12", "13"), Operator:=xlFilterValues
Rows("2:28").Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$1:$S$719").AutoFilter Field:=5
Rows("1:1").Select
Selection.AutoFilter

I see the ActiveSheet.Ranges will need to change with each incarnation of
the worksheet. So, I could probably set these to A1:S60000 as the
spreadsheet will never get beyond that many rows. But, selecting the
results
of filter - rows to delete portion is problematic. Any suggestions? Or
should I filter and set the Operator to delete? If so, what would that
look
like?


.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro/VB coding question

When I don't know the number of rows, I'll use something like this if there's a
column that can determine where the data stops:

Dim LastRow as long
....
with activesheet
'use column A to determine the last row
lastrow = .cells(.rows.count,"A").end(xlup).row
end with

Then I could use:

ActiveSheet.Range("A1:S" & lastrow).AutoFilter ....
(the dollar signs don't help in the code)

Or I just use the entire column:

activesheet.range("A:S").autofilter ...

=======
After the range is filtered, I'd use something like:

dim VisRng as range 'near the top
....
with activesheet
with .autofilter.range 'don't worry about the exact address
If .Columns(1).Cells.SpecialCells(xlCellTypeVisible). Count = 1 Then
'nothing visible
Set VisRng = Nothing
Else
'resize to avoid the header
'and come down one row
'single column of visible cells
Set VisRng = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
End If
End With
End With

if visrng is nothing then
'do nothing
else
visrng.entirerow.delete
end if

======
Untested, uncompiled. Watch for typos!



melExcel2007 wrote:

I want a macro to work for a worksheet name which will always be the same
directory and file name but the data inside worksheet will periodically
change - increase in rows/decrease in rows. # of Columns/Column names will
not change. I'm trying to filter for a non-changing set of info, then delete
the results.

Here's what I get if I record my current run:

Workbooks.Open Filename:= _
"***Directory of location and file name here***"
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$S$746").AutoFilter Field:=5,
Criteria1:=Array("10" _
, "11", "12", "13"), Operator:=xlFilterValues
Rows("2:28").Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$1:$S$719").AutoFilter Field:=5
Rows("1:1").Select
Selection.AutoFilter

I see the ActiveSheet.Ranges will need to change with each incarnation of
the worksheet. So, I could probably set these to A1:S60000 as the
spreadsheet will never get beyond that many rows. But, selecting the results
of filter - rows to delete portion is problematic. Any suggestions? Or
should I filter and set the Operator to delete? If so, what would that look
like?


--

Dave Peterson
Reply
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
Help in macro coding Sasikiran Excel Discussion (Misc queries) 3 March 24th 10 02:34 PM
converting question; function, formula, or coding? gtrask Excel Worksheet Functions 4 July 8th 08 12:25 AM
Help on macro coding for URL Eric Excel Worksheet Functions 2 March 15th 08 02:02 PM
Please help on coding the macro. Eric Excel Worksheet Functions 0 March 11th 08 03:11 PM
visual basic coding question stevie888 Excel Discussion (Misc queries) 0 November 26th 06 10:24 PM


All times are GMT +1. The time now is 11:30 PM.

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"