I am currently in the middle of making a document and trying to get it to recognize it that if the value is greater then 0 it keeps the row and puts the value in that box but if the value is less than 0 it deletes the row.
I am currently in the middle of making a document and trying to get it to recognize it that if the value is greater then 0 it keeps the row and puts the value in that box but if the value is less than 0 it deletes the row.
By "Puts the value in that box", exactly what are you saying? In that cell? Do you have a text box or a form?Originally Posted by memphis0607
If Cell A23 (Where does the value reside?) contains a value greater than zero, put the value where? And if it does not have a value greater than zero then delete the entire row?
How many rows are potentially involved 10's, 100's, 1,000's, etc?
Thanks!
Dennis
I am using Windows 7 and Office 2007, all of my posts are based on this.
Example: Cell b2 refers to cell a1. If the value in a1 is greater then 0 then it just gets put into b2. If it isn't greater then 0 then i want it to delete row 2.
Its a worksheet/workbook in excel.
Yes that is correct if it does not have a value greater than zero, delete the entire row.
And maximum 100 rows.
On my way home for the evening.
See if you can modify this to suit your needsOriginally Posted by memphis0607
Sub delRows() Dim lRow As Long lRow = Range("A65536").End(xlUp).Row While lRow > 0 If Cells(lRow, 1).Value > 0 Then Cells(lRow, 2).FormulaR1C1 = "=RC[-1]" Else Rows(lRow).Delete shift:=xlUp End If lRow = lRow - 1 Wend End Sub
Good Morning Memphis, Private messages are limited in size, thus this post.Originally Posted by memphis0607
The code I previously posted has the formula to have the B2 equal to A2. After I read your message again, I created a sample workbook with the corrected formulas and changed the routine to avoid reference errors.
When you press the button, it will start at the bottom of column A and work its way up. If the cell value is not greater than zero, it will delete the entire row; on the other hand, if the cells value is greater than zero it will place a formula in column B (next row down). The formula is simply equals column A (original row).
I am attaching that simple file with the macro insertered into a standard module. Press key combination <Alt><F11> to open the VBE Window. If the Project Explorer is not visible press <Ctrl><R> to open it so you can see what the components are in a VBA Project.
To create your own module, from the main menu select Insert > Module.
I am unsure of what your total workbook does so I set this to do exactly what I understand that was said above.
Be sure to try to work your way logically through the steps to see if you understand the routine before you run the macro.
A good way to see what happens is to make the VBE window small enough to be able to see the worksheet behind it and step through the macro. To step through, just click so the cursor is anywhere within the subroutine and press <F8>. You will see succcessive lines of code hilighted to show what is going to happen next.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks