Macro won't recognize value in cell that has If statement

Liberteric

New Member
Joined
Sep 29, 2014
Messages
28
I've been running the macro below manually. I would like a macro to test column A which contains an If statement IF(B1=E1,1,0) on each row until row A is empty.
I tried a suggestion from here before and if the value was 0, it called up this macro but the macro saw the value of 1 as a 0. If you can help, that would be great.


Sub AddLine()
' Addline Macro
'
'
Application.ScreenUpdating = False
Application.CutCopyMode = False
Range(Selection, Selection.End(xlToRight).Offset(, 13)).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveCell.Offset(-1, -4).Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.Offset(1, 1).Select
' Start New GL Code list
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("NEWGL").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1).Select
ActiveSheet.Paste
Sheets("TB").Select
Application.CutCopyMode = False
'Fill New Code data
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
ActiveCell.Offset(, 3).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.Offset(, 2).Select
ActiveCell.FormulaR1C1 = "0"
Application.CutCopyMode = False
Selection.Copy
Selection.End(xlToRight).Select
ActiveCell.Offset(1, 0).Select
Range(Selection, Selection.End(xlToLeft)).Select
ActiveCell.Offset(-1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(, -1).Select
Selection.ClearContents
Application.CutCopyMode = False

'Get Record location
ActiveCell.Offset(, 1).Select
ActiveCell.Formula = "=CELL(""address"")"
Application.CutCopyMode = False
ActiveCell.Offset(, -3).Select
Selection.Copy
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.Offset(, 3).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Copy
Sheets("NEWGL").Select
Range("D1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1).Select
ActiveSheet.Paste
Sheets("TB").Select

'Return to column E
Application.CutCopyMode = False
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
ActiveCell.Offset(, 4).Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
I changed it and it worked. I figured since it inserted the whole row rather than from row E, I would put an offset in and it worked. Thank you so much. Below is the proper macro.
Sub MyMacro()

Dim cell As Range

For Each cell In Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
If (Len(cell) = 1) And (cell.Value = 0) Then
cell.Select
ActiveCell.Offset(, 4).Select
Call AddLine
End If
Next cell

End Sub
 
Upvote 0
Are you trying to run the changes against column E based on the entry in column A?
 
Upvote 0
For some reason, I can't reply to you on your last post but I didn't want to leave you wondering.
column E is where I begin the insert of the row. I listed my last macro that did work. I changed the E's to A's, (because the macro referring to E didn't do anything) but it inserted the whole row, so I offset it 4 to the right and it worked great. I'm sorry it took so long to respond but the people that run this site are weird. They wouldn't allow my to reply to your actual post, but hopefully you'll get this. Thank you for saving days of code writing.
 
Upvote 0
I'm sorry it took so long to respond but the people that run this site are weird. They wouldn't allow my to reply to your actual post, but hopefully you'll get this.
What do you mean they wouldn't let you reply to the actual post (that is where this is now)?
Were you getting some sort of error message?
Occasionally, people get a corrupt cookie on their computer which prevents them from posting. Usually clearing out your temporary internet files, cookies, and cache will resolve that issue.
Or, if you are using a new version of Internet Explorer, you may need to use Compatibility Mode (I actually use Google Chrome).
Once in a great while, there are problems with the site (maybe undergoing some updates) where no one can post for a short period of time (or it seems really slow).

There is no one who monitors/checks the posts before they happen, so there would be no human intervention preventing you from posting. I know, because I am a Moderator of this site.
 
Upvote 0

Forum statistics

Threads
1,226,840
Messages
6,193,271
Members
453,787
Latest member
Dekowrage

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