Macro to call macro if cell = 0. Please help. Wife's job depends on it.

Liberteric

New Member
Joined
Sep 29, 2014
Messages
28
I have a macro button named "AddLine" that shifts cells down from E thru (End Right) as long as I start in column E.

I want to test each line and if A = 0, run the macro "AddLine", if not then move down a line and repeat. I tried the following but it only inserts from the first row (which doesn't equal zero).

Row A is a formula. If(Br=Er,1,0). Is my test to see if a=0 returning a fal se because it's an if rather than the actual number 0? Below is my macro.

Sub MyInsertMacro()
' Starts in E1
Range("E1").Select
Application.ScreenUpdating = False

' Find last row with data in column B
myLastRow = Cells(Rows.Count, "B").End(xlUp).Row
' Loop through all rows in column A, starting at row 1
For myRow = 1 To myLastRow Step 1
' Check to see if value in column A = 0, If true, run macro AddLine
If Cells(myRow, "A") = 0 Then
Call AddLine

End If
Next myRow

Application.ScreenUpdating = True
 
The macro recognizes A as number 0 so it runs the secondary macro. A contains =IF(b=e,1,0). It returns 1.
I don't know how else to word this but my wife is going to lose her job if I can't figure this out. I think it has something to do with what the REAL data is that A returns. PLEASE HELP ME.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
It runs the addline macro every row. It acts as if it doesn't recognize that A is not equal to 0.
I apoligize. I didn't see this. I also don't know what you meant by value2.
 
Upvote 0
Libertic, could you post an example of the data? I really don't think the problem is hard to solve - but just need to have something to go on.

So we have a macro for the cell with the formula fine; but could we have the formula and the cells it using. I.e. so that I can replicate it on my excel?

A cell doesn't just have range("A1").value but also .value2(the unformatted output), .formula, .text, etc.

You say: If(Br=Er,1,0)

Are those named ranges? Trivially "Br" =/ "Er", so what is it testing?

Maybe also> ONERROR(
If(Br=Er,1,0),0) .. etc
 
Last edited:
Upvote 0
"So we have a macro for the cell with the formula fine; but could we have the formula and the cells it using. I.e. so that I can replicate it on my excel?"

In column A I have a formula on each row that compares columns B and E.
ie: On row 1 the formula would read =IF(B1=E1,1,0)

"A cell doesn't just have range("A1").value but also .value2(the unformatted output), .formula, .text, etc."

There is no output. I start the macro on E1 then I want to move down each row and if A of the row I'm in =0, I wish to run a sub macro that inserts a row from column E to column V, then goes to the next row in column E and do it again.

"You say: If(Br=Er,1,0)

Are those named ranges? Trivially "Br" =/ "Er", so what is it testing?"

B is the column r is the current row it's in.

I have been scrolling through the worksheet until I see column A =0, I then click a button assigned the AddLine macro. I continue to do so until there are no more rows of data. I need my macro to do the scrolling and checking of column A and if it is 0, to run the AddLine macro.

Thank you for your time.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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