ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   how do I insert a row based on a function result (https://www.excelbanter.com/excel-worksheet-functions/27409-how-do-i-insert-row-based-function-result.html)

chris

how do I insert a row based on a function result
 
I want to run a a IF statement to qualify a row of data, and them if the
condition is true, I want to insert a blank row below the current row where
the fomula resides. I could also rework the formula to allow for the
insertion of the blank row to be above the current row, as well. Either would
work.

Any assistance would be great!

Dave Peterson

Formulas can return values to the cell--they can't insert rows above (or below).

chris wrote:

I want to run a a IF statement to qualify a row of data, and them if the
condition is true, I want to insert a blank row below the current row where
the fomula resides. I could also rework the formula to allow for the
insertion of the blank row to be above the current row, as well. Either would
work.

Any assistance would be great!


--

Dave Peterson

chris



"Dave Peterson" wrote:

Formulas can return values to the cell--they can't insert rows above (or below).

chris wrote:

I want to run a a IF statement to qualify a row of data, and them if the
condition is true, I want to insert a blank row below the current row where
the fomula resides. I could also rework the formula to allow for the
insertion of the blank row to be above the current row, as well. Either would
work.

Any assistance would be great!


--

Dave Peterson

I understand. Then, is there a way to insert a blank row from a Macro.. one
that would look at a one consistent cell within a row to qualify the
insertion (ie...for any row where column A contains "X", then insert a row??

Thanks.

Dave Peterson

Option Explicit
Sub testme()

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim wks As Worksheet

Set wks = Worksheets("sheet1")
With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = LastRow To FirstRow Step -1
If LCase(.Cells(iRow, "A").Value) = LCase("x") Then
.Rows(iRow + 1).EntireRow.Insert
End If
Next iRow
End With

End Sub

Will insert a new row after if it finds an X in column A. (after that row).

chris wrote:

"Dave Peterson" wrote:

Formulas can return values to the cell--they can't insert rows above (or below).

chris wrote:

I want to run a a IF statement to qualify a row of data, and them if the
condition is true, I want to insert a blank row below the current row where
the fomula resides. I could also rework the formula to allow for the
insertion of the blank row to be above the current row, as well. Either would
work.

Any assistance would be great!


--

Dave Peterson

I understand. Then, is there a way to insert a blank row from a Macro.. one
that would look at a one consistent cell within a row to qualify the
insertion (ie...for any row where column A contains "X", then insert a row??

Thanks.


--

Dave Peterson


All times are GMT +1. The time now is 12:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com