thunderfoot123
New Member
- Joined
- Feb 14, 2012
- Messages
- 3
I am completely new to VBA and teaching myself. Access is where I am comfortable but I need to do this for other users who use excel.
I am working in Excel 2007. I have a sheet of data from columns A to column L. I need to create new headers, create an “if then” statement that calculates simple subtraction and if the answer is >=0 then give me a blank cell. The statement needs to be auto filled through the worksheet of active data. ( The rows of data can change daily as we get this spreadsheet) and finally if all the cells in a row for column M,N,O,P and Q are blank then delete the whole row.
1. Create row headers for columns M to Q that read as follows
M=003
N=007
O=009
P=010
Q=011
2. I need an “if then” statement to auto fill the range of M2 to column Q and whatever the last row of active data is located in column A. Following is the formula excel version
If (C2-H2>=0,””,C2-H2)
3. Filter columns M,N,O,P and Q for blanks and delete those rows and then filter M,N,O,P and Q back to show the negative numbers
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
This macro needs to be easy for another person to open the excel sheet they get daily and just run the macro.
I did a “record macro” of everything I listed above which works perfectly except the number of rows will change each day so I the person cannot use that same macro each time. I don’t know how to change the macro to perform it on the active data (or anything with data in column A)
This is the recorded macro if that helps. Sorry for the longwinded description. I would appreciate any help.
Sub Macro4()<o></o>
'<o></o>
' Macro4 Macro<o></o>
'<o></o>
<o> </o>
'<o></o>
Range("M1:Q1").Select<o></o>
Selection.NumberFormat = "@"<o></o>
Range("M1").Select<o></o>
ActiveCell.FormulaR1C1 = "003"<o></o>
Range("N1").Select<o></o>
ActiveCell.FormulaR1C1 = "007"<o></o>
Range("O1").Select<o></o>
ActiveCell.FormulaR1C1 = "009"<o></o>
Range("P1").Select<o></o>
ActiveCell.FormulaR1C1 = "010"<o></o>
Range("Q1").Select<o></o>
ActiveCell.FormulaR1C1 = "011"<o></o>
Range("M2").Select<o></o>
ActiveCell.FormulaR1C1 = "=IF(RC[-10]-RC[-5]>=0,"""",RC[-10]-RC[-5])"<o></o>
Range("M2").Select<o></o>
Selection.AutoFill Destination:=Range("M2:M802"), Type:=xlFillDefault<o></o>
Range("M2:M802").Select<o></o>
Selection.AutoFill Destination:=Range("M2:Q802"), Type:=xlFillDefault<o></o>
Range("M2:Q802").Select<o></o>
ActiveWindow.ScrollRow = 779<o></o>
ActiveWindow.ScrollRow = 773<o></o>
ActiveWindow.ScrollRow = 768<o></o>
ActiveWindow.ScrollRow = 757<o></o>
ActiveWindow.ScrollRow = 745<o></o>
ActiveWindow.ScrollRow = 732<o></o>
ActiveWindow.ScrollRow = 718<o></o>
ActiveWindow.ScrollRow = 702<o></o>
ActiveWindow.ScrollRow = 685<o></o>
ActiveWindow.ScrollRow = 669<o></o>
ActiveWindow.ScrollRow = 649<o></o>
ActiveWindow.ScrollRow = 628<o></o>
ActiveWindow.ScrollRow = 609<o></o>
ActiveWindow.ScrollRow = 583<o></o>
ActiveWindow.ScrollRow = 560<o></o>
ActiveWindow.ScrollRow = 538<o></o>
ActiveWindow.ScrollRow = 518<o></o>
ActiveWindow.ScrollRow = 493<o></o>
ActiveWindow.ScrollRow = 462<o></o>
ActiveWindow.ScrollRow = 437<o></o>
ActiveWindow.ScrollRow = 413<o></o>
ActiveWindow.ScrollRow = 391<o></o>
ActiveWindow.ScrollRow = 370<o></o>
ActiveWindow.ScrollRow = 348<o></o>
ActiveWindow.ScrollRow = 327<o></o>
ActiveWindow.ScrollRow = 307<o></o>
ActiveWindow.ScrollRow = 287<o></o>
ActiveWindow.ScrollRow = 272<o></o>
ActiveWindow.ScrollRow = 260<o></o>
ActiveWindow.ScrollRow = 242<o></o>
ActiveWindow.ScrollRow = 227<o></o>
ActiveWindow.ScrollRow = 211<o></o>
ActiveWindow.ScrollRow = 198<o></o>
ActiveWindow.ScrollRow = 185<o></o>
ActiveWindow.ScrollRow = 169<o></o>
ActiveWindow.ScrollRow = 157<o></o>
ActiveWindow.ScrollRow = 145<o></o>
ActiveWindow.ScrollRow = 135<o></o>
ActiveWindow.ScrollRow = 128<o></o>
ActiveWindow.ScrollRow = 119<o></o>
ActiveWindow.ScrollRow = 112<o></o>
ActiveWindow.ScrollRow = 107<o></o>
ActiveWindow.ScrollRow = 101<o></o>
ActiveWindow.ScrollRow = 97<o></o>
ActiveWindow.ScrollRow = 93<o></o>
ActiveWindow.ScrollRow = 89<o></o>
ActiveWindow.ScrollRow = 86<o></o>
ActiveWindow.ScrollRow = 84<o></o>
ActiveWindow.ScrollRow = 81<o></o>
ActiveWindow.ScrollRow = 77<o></o>
ActiveWindow.ScrollRow = 76<o></o>
ActiveWindow.ScrollRow = 75<o></o>
ActiveWindow.ScrollRow = 74<o></o>
ActiveWindow.ScrollRow = 73<o></o>
ActiveWindow.ScrollRow = 71<o></o>
ActiveWindow.ScrollRow = 70<o></o>
ActiveWindow.ScrollRow = 68<o></o>
ActiveWindow.ScrollRow = 67<o></o>
ActiveWindow.ScrollRow = 63<o></o>
ActiveWindow.ScrollRow = 60<o></o>
ActiveWindow.ScrollRow = 57<o></o>
ActiveWindow.ScrollRow = 52<o></o>
ActiveWindow.ScrollRow = 48<o></o>
ActiveWindow.ScrollRow = 44<o></o>
ActiveWindow.ScrollRow = 37<o></o>
ActiveWindow.ScrollRow = 32<o></o>
ActiveWindow.ScrollRow = 26<o></o>
ActiveWindow.ScrollRow = 22<o></o>
ActiveWindow.ScrollRow = 17<o></o>
ActiveWindow.ScrollRow = 13<o></o>
ActiveWindow.ScrollRow = 6<o></o>
ActiveWindow.ScrollRow = 2<o></o>
ActiveWindow.ScrollRow = 1<o></o>
Rows("1:1").Select<o></o>
Selection.AutoFilter<o></o>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=13, Criteria1:="="<o></o>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=14, Criteria1:="="<o></o>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=15, Criteria1:="="<o></o>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=16, Criteria1:="="<o></o>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=17, Criteria1:="="<o></o>
Rows("2:801").Select<o></o>
Selection.Delete Shift:=xlUp<o></o>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=13<o></o>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=14<o></o>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=15<o></o>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=16<o></o>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=17<o></o>
End Sub<o></o>
I am working in Excel 2007. I have a sheet of data from columns A to column L. I need to create new headers, create an “if then” statement that calculates simple subtraction and if the answer is >=0 then give me a blank cell. The statement needs to be auto filled through the worksheet of active data. ( The rows of data can change daily as we get this spreadsheet) and finally if all the cells in a row for column M,N,O,P and Q are blank then delete the whole row.
1. Create row headers for columns M to Q that read as follows
M=003
N=007
O=009
P=010
Q=011
2. I need an “if then” statement to auto fill the range of M2 to column Q and whatever the last row of active data is located in column A. Following is the formula excel version
If (C2-H2>=0,””,C2-H2)
3. Filter columns M,N,O,P and Q for blanks and delete those rows and then filter M,N,O,P and Q back to show the negative numbers
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
This macro needs to be easy for another person to open the excel sheet they get daily and just run the macro.
I did a “record macro” of everything I listed above which works perfectly except the number of rows will change each day so I the person cannot use that same macro each time. I don’t know how to change the macro to perform it on the active data (or anything with data in column A)
This is the recorded macro if that helps. Sorry for the longwinded description. I would appreciate any help.
Sub Macro4()<o></o>
'<o></o>
' Macro4 Macro<o></o>
'<o></o>
<o> </o>
'<o></o>
Range("M1:Q1").Select<o></o>
Selection.NumberFormat = "@"<o></o>
Range("M1").Select<o></o>
ActiveCell.FormulaR1C1 = "003"<o></o>
Range("N1").Select<o></o>
ActiveCell.FormulaR1C1 = "007"<o></o>
Range("O1").Select<o></o>
ActiveCell.FormulaR1C1 = "009"<o></o>
Range("P1").Select<o></o>
ActiveCell.FormulaR1C1 = "010"<o></o>
Range("Q1").Select<o></o>
ActiveCell.FormulaR1C1 = "011"<o></o>
Range("M2").Select<o></o>
ActiveCell.FormulaR1C1 = "=IF(RC[-10]-RC[-5]>=0,"""",RC[-10]-RC[-5])"<o></o>
Range("M2").Select<o></o>
Selection.AutoFill Destination:=Range("M2:M802"), Type:=xlFillDefault<o></o>
Range("M2:M802").Select<o></o>
Selection.AutoFill Destination:=Range("M2:Q802"), Type:=xlFillDefault<o></o>
Range("M2:Q802").Select<o></o>
ActiveWindow.ScrollRow = 779<o></o>
ActiveWindow.ScrollRow = 773<o></o>
ActiveWindow.ScrollRow = 768<o></o>
ActiveWindow.ScrollRow = 757<o></o>
ActiveWindow.ScrollRow = 745<o></o>
ActiveWindow.ScrollRow = 732<o></o>
ActiveWindow.ScrollRow = 718<o></o>
ActiveWindow.ScrollRow = 702<o></o>
ActiveWindow.ScrollRow = 685<o></o>
ActiveWindow.ScrollRow = 669<o></o>
ActiveWindow.ScrollRow = 649<o></o>
ActiveWindow.ScrollRow = 628<o></o>
ActiveWindow.ScrollRow = 609<o></o>
ActiveWindow.ScrollRow = 583<o></o>
ActiveWindow.ScrollRow = 560<o></o>
ActiveWindow.ScrollRow = 538<o></o>
ActiveWindow.ScrollRow = 518<o></o>
ActiveWindow.ScrollRow = 493<o></o>
ActiveWindow.ScrollRow = 462<o></o>
ActiveWindow.ScrollRow = 437<o></o>
ActiveWindow.ScrollRow = 413<o></o>
ActiveWindow.ScrollRow = 391<o></o>
ActiveWindow.ScrollRow = 370<o></o>
ActiveWindow.ScrollRow = 348<o></o>
ActiveWindow.ScrollRow = 327<o></o>
ActiveWindow.ScrollRow = 307<o></o>
ActiveWindow.ScrollRow = 287<o></o>
ActiveWindow.ScrollRow = 272<o></o>
ActiveWindow.ScrollRow = 260<o></o>
ActiveWindow.ScrollRow = 242<o></o>
ActiveWindow.ScrollRow = 227<o></o>
ActiveWindow.ScrollRow = 211<o></o>
ActiveWindow.ScrollRow = 198<o></o>
ActiveWindow.ScrollRow = 185<o></o>
ActiveWindow.ScrollRow = 169<o></o>
ActiveWindow.ScrollRow = 157<o></o>
ActiveWindow.ScrollRow = 145<o></o>
ActiveWindow.ScrollRow = 135<o></o>
ActiveWindow.ScrollRow = 128<o></o>
ActiveWindow.ScrollRow = 119<o></o>
ActiveWindow.ScrollRow = 112<o></o>
ActiveWindow.ScrollRow = 107<o></o>
ActiveWindow.ScrollRow = 101<o></o>
ActiveWindow.ScrollRow = 97<o></o>
ActiveWindow.ScrollRow = 93<o></o>
ActiveWindow.ScrollRow = 89<o></o>
ActiveWindow.ScrollRow = 86<o></o>
ActiveWindow.ScrollRow = 84<o></o>
ActiveWindow.ScrollRow = 81<o></o>
ActiveWindow.ScrollRow = 77<o></o>
ActiveWindow.ScrollRow = 76<o></o>
ActiveWindow.ScrollRow = 75<o></o>
ActiveWindow.ScrollRow = 74<o></o>
ActiveWindow.ScrollRow = 73<o></o>
ActiveWindow.ScrollRow = 71<o></o>
ActiveWindow.ScrollRow = 70<o></o>
ActiveWindow.ScrollRow = 68<o></o>
ActiveWindow.ScrollRow = 67<o></o>
ActiveWindow.ScrollRow = 63<o></o>
ActiveWindow.ScrollRow = 60<o></o>
ActiveWindow.ScrollRow = 57<o></o>
ActiveWindow.ScrollRow = 52<o></o>
ActiveWindow.ScrollRow = 48<o></o>
ActiveWindow.ScrollRow = 44<o></o>
ActiveWindow.ScrollRow = 37<o></o>
ActiveWindow.ScrollRow = 32<o></o>
ActiveWindow.ScrollRow = 26<o></o>
ActiveWindow.ScrollRow = 22<o></o>
ActiveWindow.ScrollRow = 17<o></o>
ActiveWindow.ScrollRow = 13<o></o>
ActiveWindow.ScrollRow = 6<o></o>
ActiveWindow.ScrollRow = 2<o></o>
ActiveWindow.ScrollRow = 1<o></o>
Rows("1:1").Select<o></o>
Selection.AutoFilter<o></o>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=13, Criteria1:="="<o></o>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=14, Criteria1:="="<o></o>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=15, Criteria1:="="<o></o>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=16, Criteria1:="="<o></o>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=17, Criteria1:="="<o></o>
Rows("2:801").Select<o></o>
Selection.Delete Shift:=xlUp<o></o>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=13<o></o>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=14<o></o>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=15<o></o>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=16<o></o>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=17<o></o>
End Sub<o></o>