LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default If value is equal, if not a blank row is inserted.

If you placed it as I described, then
the macro should run everytime the sheet is recalculated.

This is consistent with your concept of using a formula to do the work.

I did note I had a typo in the code. This is the tested revision:

Private Sub Worksheet_Calculate()
Dim lastrow As Long
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
For i = lastrow To 2 Step -1
If Application.CountA(Cells(i, "B"), Cells(i, "D"), Cells(i, "E")) < 0
And _
Application.CountA(Cells(i - 1, "B"), Cells(i - 1, "D"), Cells(i - 1,
"E")) < 0 Then
If Cells(i, "B") < Cells(i - 1, "B") Or Cells(i, "D") < Cells(i - 1,
"D") _
Or Cells(i, "E") < Cells(i - 1, "E") Then
Rows(i).EntireRow.Insert
End If
End If
Next
End Sub

It worked for me when I hit F9 to force a calculate.

However, I am not sure what you are doing or how you will be changing your
worksheet. If this is a one time thing, then you don't want to use the
calculate event. You would go into the VBE (alt + F11) and choose Insert =
Module from the menu. In the module you would put this code:

Public Sub AddRows()
Dim lastrow As Long
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
For i = lastrow To 2 Step -1
If Application.CountA(Cells(i, "B"), Cells(i, "D"), Cells(i, "E")) < 0
And _
Application.CountA(Cells(i - 1, "B"), Cells(i - 1, "D"), Cells(i - 1,
"E")) < 0 Then
If Cells(i, "B") < Cells(i - 1, "B") Or Cells(i, "D") < Cells(i - 1,
"D") _
Or Cells(i, "E") < Cells(i - 1, "E") Then
Rows(i).EntireRow.Insert
End If
End If
Next
End Sub

the go back to excel and if you wanted to run it you would go

Tools=Macro=Macros, select Addrows and hit the run button.

or stay in the VBE, click in the macro and hit F5 as you describe.

Whatever you do, like any other change to a workbook, you need to save the
workbook to save the macro.

--
Regards,
Tom Ogilvy


"Emajination" wrote:

Thank you Tom for the quick response

That was very helpful. Please forgive my lack of knowledge, but I'm
unsure how to get the Macro to work. This is actually my first time
creating a macro. I've pasted the code into the VBA, but I'm sure if I
should save the file, or click Run (F5).

Any assistance would be helpful.


 
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
Import csv file - blank lines inserted Dave Peterson Excel Discussion (Misc queries) 0 February 21st 07 01:56 AM
Why does blank text equal 0? [email protected] Excel Worksheet Functions 6 October 12th 06 03:47 AM
I don't want blank tp equal zero lovemark Excel Discussion (Misc queries) 3 May 19th 06 08:19 PM
Blank space gets inserted after text Ros M New Users to Excel 2 September 26th 05 02:07 PM
Formula to equal Blank Jacqui Hurst Excel Programming 3 July 29th 03 11:57 AM


All times are GMT +1. The time now is 05:26 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"