VBA/macro-range changes daily-use formula and delete blank lines

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-com:office:office" /><o:p> </o:p>
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:p></o:p>
'<o:p></o:p>
' Macro4 Macro<o:p></o:p>
'<o:p></o:p>
<o:p> </o:p>
'<o:p></o:p>
Range("M1:Q1").Select<o:p></o:p>
Selection.NumberFormat = "@"<o:p></o:p>
Range("M1").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "003"<o:p></o:p>
Range("N1").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "007"<o:p></o:p>
Range("O1").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "009"<o:p></o:p>
Range("P1").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "010"<o:p></o:p>
Range("Q1").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "011"<o:p></o:p>
Range("M2").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "=IF(RC[-10]-RC[-5]>=0,"""",RC[-10]-RC[-5])"<o:p></o:p>
Range("M2").Select<o:p></o:p>
Selection.AutoFill Destination:=Range("M2:M802"), Type:=xlFillDefault<o:p></o:p>
Range("M2:M802").Select<o:p></o:p>
Selection.AutoFill Destination:=Range("M2:Q802"), Type:=xlFillDefault<o:p></o:p>
Range("M2:Q802").Select<o:p></o:p>
ActiveWindow.ScrollRow = 779<o:p></o:p>
ActiveWindow.ScrollRow = 773<o:p></o:p>
ActiveWindow.ScrollRow = 768<o:p></o:p>
ActiveWindow.ScrollRow = 757<o:p></o:p>
ActiveWindow.ScrollRow = 745<o:p></o:p>
ActiveWindow.ScrollRow = 732<o:p></o:p>
ActiveWindow.ScrollRow = 718<o:p></o:p>
ActiveWindow.ScrollRow = 702<o:p></o:p>
ActiveWindow.ScrollRow = 685<o:p></o:p>
ActiveWindow.ScrollRow = 669<o:p></o:p>
ActiveWindow.ScrollRow = 649<o:p></o:p>
ActiveWindow.ScrollRow = 628<o:p></o:p>
ActiveWindow.ScrollRow = 609<o:p></o:p>
ActiveWindow.ScrollRow = 583<o:p></o:p>
ActiveWindow.ScrollRow = 560<o:p></o:p>
ActiveWindow.ScrollRow = 538<o:p></o:p>
ActiveWindow.ScrollRow = 518<o:p></o:p>
ActiveWindow.ScrollRow = 493<o:p></o:p>
ActiveWindow.ScrollRow = 462<o:p></o:p>
ActiveWindow.ScrollRow = 437<o:p></o:p>
ActiveWindow.ScrollRow = 413<o:p></o:p>
ActiveWindow.ScrollRow = 391<o:p></o:p>
ActiveWindow.ScrollRow = 370<o:p></o:p>
ActiveWindow.ScrollRow = 348<o:p></o:p>
ActiveWindow.ScrollRow = 327<o:p></o:p>
ActiveWindow.ScrollRow = 307<o:p></o:p>
ActiveWindow.ScrollRow = 287<o:p></o:p>
ActiveWindow.ScrollRow = 272<o:p></o:p>
ActiveWindow.ScrollRow = 260<o:p></o:p>
ActiveWindow.ScrollRow = 242<o:p></o:p>
ActiveWindow.ScrollRow = 227<o:p></o:p>
ActiveWindow.ScrollRow = 211<o:p></o:p>
ActiveWindow.ScrollRow = 198<o:p></o:p>
ActiveWindow.ScrollRow = 185<o:p></o:p>
ActiveWindow.ScrollRow = 169<o:p></o:p>
ActiveWindow.ScrollRow = 157<o:p></o:p>
ActiveWindow.ScrollRow = 145<o:p></o:p>
ActiveWindow.ScrollRow = 135<o:p></o:p>
ActiveWindow.ScrollRow = 128<o:p></o:p>
ActiveWindow.ScrollRow = 119<o:p></o:p>
ActiveWindow.ScrollRow = 112<o:p></o:p>
ActiveWindow.ScrollRow = 107<o:p></o:p>
ActiveWindow.ScrollRow = 101<o:p></o:p>
ActiveWindow.ScrollRow = 97<o:p></o:p>
ActiveWindow.ScrollRow = 93<o:p></o:p>
ActiveWindow.ScrollRow = 89<o:p></o:p>
ActiveWindow.ScrollRow = 86<o:p></o:p>
ActiveWindow.ScrollRow = 84<o:p></o:p>
ActiveWindow.ScrollRow = 81<o:p></o:p>
ActiveWindow.ScrollRow = 77<o:p></o:p>
ActiveWindow.ScrollRow = 76<o:p></o:p>
ActiveWindow.ScrollRow = 75<o:p></o:p>
ActiveWindow.ScrollRow = 74<o:p></o:p>
ActiveWindow.ScrollRow = 73<o:p></o:p>
ActiveWindow.ScrollRow = 71<o:p></o:p>
ActiveWindow.ScrollRow = 70<o:p></o:p>
ActiveWindow.ScrollRow = 68<o:p></o:p>
ActiveWindow.ScrollRow = 67<o:p></o:p>
ActiveWindow.ScrollRow = 63<o:p></o:p>
ActiveWindow.ScrollRow = 60<o:p></o:p>
ActiveWindow.ScrollRow = 57<o:p></o:p>
ActiveWindow.ScrollRow = 52<o:p></o:p>
ActiveWindow.ScrollRow = 48<o:p></o:p>
ActiveWindow.ScrollRow = 44<o:p></o:p>
ActiveWindow.ScrollRow = 37<o:p></o:p>
ActiveWindow.ScrollRow = 32<o:p></o:p>
ActiveWindow.ScrollRow = 26<o:p></o:p>
ActiveWindow.ScrollRow = 22<o:p></o:p>
ActiveWindow.ScrollRow = 17<o:p></o:p>
ActiveWindow.ScrollRow = 13<o:p></o:p>
ActiveWindow.ScrollRow = 6<o:p></o:p>
ActiveWindow.ScrollRow = 2<o:p></o:p>
ActiveWindow.ScrollRow = 1<o:p></o:p>
Rows("1:1").Select<o:p></o:p>
Selection.AutoFilter<o:p></o:p>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=13, Criteria1:="="<o:p></o:p>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=14, Criteria1:="="<o:p></o:p>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=15, Criteria1:="="<o:p></o:p>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=16, Criteria1:="="<o:p></o:p>
ActiveSheet.Range("$A$1:$Q$802").AutoFilter Field:=17, Criteria1:="="<o:p></o:p>
Rows("2:801").Select<o:p></o:p>
Selection.Delete Shift:=xlUp<o:p></o:p>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=13<o:p></o:p>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=14<o:p></o:p>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=15<o:p></o:p>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=16<o:p></o:p>
ActiveSheet.Range("$A$1:$Q$413").AutoFilter Field:=17<o:p></o:p>
End Sub<o:p></o:p>
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Still have not received a response on this. Hoping someone has anwers or help soon. Need this by next week. I was able to come up with the following which add my "if then" formula to column M to whatever the last active cell (locared in column A or 1) is. But still can't get it to go over to Q and down to the last cell. Please help. Thanks

Range("M2").Select<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
ActiveCell.FormulaR1C1 = "=IF(RC[-10]-RC[-5]>=0,"""",RC[-10]-RC[-5])"<o:p></o:p>
Selection.AutoFill Destination:=Range("M2:M" & Cells(Rows.Count, 1).End(xlUp).Row)<o:p></o:p>
Range("M2:M" & Cells(Rows.Count, 1).End(xlUp).Row).Select<o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,224,536
Messages
6,179,402
Members
452,909
Latest member
VickiS

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