Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 187
Default help me clean up this code

I have the following macro that needs to be cleaned up a bit (part of
the code was generated using the macro recorder; this is the stuff
that I think needs to be cleaned up.

Following is the code:

Option Explicit

Sub ParseELR()
'Parses the ELR report, filters it, copies the filtered records,
pastes them into a new workbook
'and prompts the user to save the file to a specific location
Dim myFileName As Variant

Range("A3").Select
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.ShowAllData
End If
Range("T2").Select
ActiveCell.FormulaR1C1 = "=IF(AND(ISNUMBER(MATCH(LEFT(RC[-18],
3),'[ELR expense account identification.xls]Sheet1'!
R2C1:R12C1,0)),ISNUMBER(MATCH(RC[-17],'[Frank''s expense codes--GDCS
and non-GDCS.xls]Sheet1'!R2C1:R39C1,0))),""Extract"","""")"
'Applies the filter criteria to each row; if BOTH conditions
return TRUE, "Extract" is returned in Column T

'THIS IS THE SECTION THAT NEEDS TO BE CLEANED UP
Range("T2:T65000").Select
Selection.FillDown
Selection.End(xlUp).Select
Selection.AutoFilter Field:=20, Criteria1:="Extract"
'Runs autofilter on the value "extract" in Column T
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
'END SECTION THAT NEEDS TO BE CLEANED UP

myFileName = Application.GetSaveAsFilename
If myFileName = False Then
Exit Sub
End If
ActiveWorkbook.SaveAs Filename:=myFileName,
FileFormat:=xlWorkbookNormal
End Sub

Thanks,

Dave

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default help me clean up this code

Dave,

Not sure what your code does, since you did not describe the worksheet layout. But, try the macro
below.

HTH,
Bernie
MS Excel MVP

Sub ParseELR()
'Parses the ELR report, filters it, copies the filtered records,
'pastes them into a new workbook
'and prompts the user to save the file to a specific location
Dim myFileName As String
Dim myRow As Long
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.ShowAllData
End If

myRow = Cells(Rows.Count, 2).End(xlUp).Row

'Applies the filter criteria to each row;
'if BOTH conditions return TRUE,
'"Extract" is returned in Column T
Range("T2:T" & myRow).FormulaR1C1 = "=IF(AND(ISNUMBER(MATCH(LEFT(RC[-18],3)," _
& "'[ELR expense account identification.xls]Sheet1'!R2C1:R12C1,0))," & _
"ISNUMBER(MATCH(RC[-17],'[Frank''s expense codes--GDCS and non-GDCS.xls]" & _
"Sheet1'!R2C1:R39C1,0))),""Extract"","""")"

Range("T1:T" & myRow).AutoFilter Field:=1, Criteria1:="Extract"

'Runs autofilter on the value "extract" in Column T
Range("T2:T" & myRow).EntireRow.SpecialCells(xlCellTypeVisible).C opy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
'END SECTION THAT NEEDS TO BE CLEANED UP

myFileName = Application.GetSaveAsFilename
If myFileName = False Then
Exit Sub
End If
ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal
End Sub


"Dave F" wrote in message
oups.com...
I have the following macro that needs to be cleaned up a bit (part of
the code was generated using the macro recorder; this is the stuff
that I think needs to be cleaned up.

Following is the code:

Option Explicit

Sub ParseELR()
'Parses the ELR report, filters it, copies the filtered records,
pastes them into a new workbook
'and prompts the user to save the file to a specific location
Dim myFileName As Variant

Range("A3").Select
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.ShowAllData
End If
Range("T2").Select
ActiveCell.FormulaR1C1 = "=IF(AND(ISNUMBER(MATCH(LEFT(RC[-18],
3),'[ELR expense account identification.xls]Sheet1'!
R2C1:R12C1,0)),ISNUMBER(MATCH(RC[-17],'[Frank''s expense codes--GDCS
and non-GDCS.xls]Sheet1'!R2C1:R39C1,0))),""Extract"","""")"
'Applies the filter criteria to each row; if BOTH conditions
return TRUE, "Extract" is returned in Column T

'THIS IS THE SECTION THAT NEEDS TO BE CLEANED UP
Range("T2:T65000").Select
Selection.FillDown
Selection.End(xlUp).Select
Selection.AutoFilter Field:=20, Criteria1:="Extract"
'Runs autofilter on the value "extract" in Column T
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
'END SECTION THAT NEEDS TO BE CLEANED UP

myFileName = Application.GetSaveAsFilename
If myFileName = False Then
Exit Sub
End If
ActiveWorkbook.SaveAs Filename:=myFileName,
FileFormat:=xlWorkbookNormal
End Sub

Thanks,

Dave



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 187
Default help me clean up this code

Sorry. The worksheet layout is a table, range A1:S65000. The formula
in the macro is entered in T2 and filled down to T65000. The formula
performs a test on data in column B and a second test on column C of
the aforementioned range, and where both tests resolve to TRUE, the
value "extract" is returned in column T for each row.

These two tests a (1) do the three left characters in B2 match any
value in the range B2:B12 in an external worksheet, and (2) does the
value in C2 match any value in the range B2:B39 in a second external
worksheet.

Then the macro is supposed to filter this huge table on the "extract"
value in column T, copy the filtered data, paste in a new worksheet,
and prompt the user for a file name/save location.

The same thing could be done with SQL by relating the three tables of
data to one another, but the point of this exercise is that I can just
put a button on this report and a non-tech user would just need to
click the button and have the data filtered and extracted.

Your code is helpful, though, thanks. It appears to do exactly what I
want.

Dave

On Jun 14, 1:12 pm, "Bernie Deitrick" <deitbe @ consumer dot org
wrote:
Dave,

Not sure what your code does, since you did not describe the worksheet layout. But, try the macro
below.

HTH,
Bernie
MS Excel MVP

Sub ParseELR()
'Parses the ELR report, filters it, copies the filtered records,
'pastes them into a new workbook
'and prompts the user to save the file to a specific location
Dim myFileName As String
Dim myRow As Long
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.ShowAllData
End If

myRow = Cells(Rows.Count, 2).End(xlUp).Row

'Applies the filter criteria to each row;
'if BOTH conditions return TRUE,
'"Extract" is returned in Column T
Range("T2:T" & myRow).FormulaR1C1 = "=IF(AND(ISNUMBER(MATCH(LEFT(RC[-18],3)," _
& "'[ELR expense account identification.xls]Sheet1'!R2C1:R12C1,0))," & _
"ISNUMBER(MATCH(RC[-17],'[Frank''s expense codes--GDCS and non-GDCS.xls]" & _
"Sheet1'!R2C1:R39C1,0))),""Extract"","""")"

Range("T1:T" & myRow).AutoFilter Field:=1, Criteria1:="Extract"

'Runs autofilter on the value "extract" in Column T
Range("T2:T" & myRow).EntireRow.SpecialCells(xlCellTypeVisible).C opy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
'END SECTION THAT NEEDS TO BE CLEANED UP

myFileName = Application.GetSaveAsFilename
If myFileName = False Then
Exit Sub
End If
ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal
End Sub

"Dave F" wrote in message

oups.com...



I have the following macro that needs to be cleaned up a bit (part of
the code was generated using the macro recorder; this is the stuff
that I think needs to be cleaned up.


Following is the code:


Option Explicit


Sub ParseELR()
'Parses the ELR report, filters it, copies the filtered records,
pastes them into a new workbook
'and prompts the user to save the file to a specific location
Dim myFileName As Variant


Range("A3").Select
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.ShowAllData
End If
Range("T2").Select
ActiveCell.FormulaR1C1 = "=IF(AND(ISNUMBER(MATCH(LEFT(RC[-18],
3),'[ELR expense account identification.xls]Sheet1'!
R2C1:R12C1,0)),ISNUMBER(MATCH(RC[-17],'[Frank''s expense codes--GDCS
and non-GDCS.xls]Sheet1'!R2C1:R39C1,0))),""Extract"","""")"
'Applies the filter criteria to each row; if BOTH conditions
return TRUE, "Extract" is returned in Column T


'THIS IS THE SECTION THAT NEEDS TO BE CLEANED UP
Range("T2:T65000").Select
Selection.FillDown
Selection.End(xlUp).Select
Selection.AutoFilter Field:=20, Criteria1:="Extract"
'Runs autofilter on the value "extract" in Column T
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
'END SECTION THAT NEEDS TO BE CLEANED UP


myFileName = Application.GetSaveAsFilename
If myFileName = False Then
Exit Sub
End If
ActiveWorkbook.SaveAs Filename:=myFileName,
FileFormat:=xlWorkbookNormal
End Sub


Thanks,


Dave- Hide quoted text -


- Show quoted text -



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
clean up code a little terilad Excel Discussion (Misc queries) 12 April 12th 10 07:35 PM
Clean up code. Tim Excel Programming 2 October 1st 04 05:37 PM
Help clean up this code... scottnshelly[_32_] Excel Programming 8 June 21st 04 09:30 PM
Clean up code using WITHs Richard[_28_] Excel Programming 2 April 30th 04 02:59 AM
Plase help me clean up my code jasonsweeney[_14_] Excel Programming 1 January 22nd 04 07:47 PM


All times are GMT +1. The time now is 01:15 PM.

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

About Us

"It's about Microsoft Excel"