Hi All:
I'm in the process of creating a macro that, among other things, copies a line of data (found by searching for a row header, in this case "Depreciation - mach and equip impairments") from one tab ("Depreciation Macro"), finds the matching line on a different tab ("Variance"), and pastes the data line into the corresponding line on the "Variance" tab. This works fine when there is an already existing "Deprec exp mach and equip impairments" line on the "Variance" tab. However, due to the nature of the workbooks I'm using, there will not always be a matching line on the "Variance" tab. What I want to do is to have the macro run like the code below when the matching line is found on the "Variance" tab. And when there is NO matching line found, I want to insert and create said matching line on the "Variance" tab, and proceed to paste the data. Is there a simple way to do this?
I know how to create the code that will insert the line; what I'm really looking for is a code that will say, "If the corresponding line on "Variance" is found, paste the data; if the line is not found on "Variance," insert a line and then paste the data." Thanks in advance for any help received!
Sheets("Depreciation Macro").Select
ActiveWorkbook.Worksheets("Depreciation Macro").Columns(11).Find(" Depreciation - mach and equip impairments ").Select
ActiveCell.Offset(, 1).Resize(1, 23).Copy
Sheets("Variance").Select
Cells.Find(What:="Deprec exp mach and equip impairments", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
I'm in the process of creating a macro that, among other things, copies a line of data (found by searching for a row header, in this case "Depreciation - mach and equip impairments") from one tab ("Depreciation Macro"), finds the matching line on a different tab ("Variance"), and pastes the data line into the corresponding line on the "Variance" tab. This works fine when there is an already existing "Deprec exp mach and equip impairments" line on the "Variance" tab. However, due to the nature of the workbooks I'm using, there will not always be a matching line on the "Variance" tab. What I want to do is to have the macro run like the code below when the matching line is found on the "Variance" tab. And when there is NO matching line found, I want to insert and create said matching line on the "Variance" tab, and proceed to paste the data. Is there a simple way to do this?
I know how to create the code that will insert the line; what I'm really looking for is a code that will say, "If the corresponding line on "Variance" is found, paste the data; if the line is not found on "Variance," insert a line and then paste the data." Thanks in advance for any help received!
Sheets("Depreciation Macro").Select
ActiveWorkbook.Worksheets("Depreciation Macro").Columns(11).Find(" Depreciation - mach and equip impairments ").Select
ActiveCell.Offset(, 1).Resize(1, 23).Copy
Sheets("Variance").Select
Cells.Find(What:="Deprec exp mach and equip impairments", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False