W
weston.perkins
I am presently building a complex model in Excel and I would like to
create a macro that would insert a new line into a project cost
catagory. This line would then need to be inserted throughout the
rest of the model to be referenced. I have created a step by step
recorded macro as to the functionality and formating changes needed as
the new line item is placed throughout the workbook. The problem
occurs when selecting the bottom of a set catagory of costs. Instead
of referencing the bottom of the set each time the macro is run, it
continually inserts the line item on a specific row number. I do not
have enough knowledge of VBA and would appreciate any help that could
shed some light on fixing this problem. Below is a copy of the VBA
code of the recorded step by step macro.
Sub LandDevelopCostsAdd()
'
' LandDevelopCostsAdd Macro
' Macro recorded 3/20/2007 by wperkins
'
'
Rows("30:30").Select
Selection.Insert Shift:=xlDown
Rows("29:29").Select
Selection.Copy
Rows("30:30").Select
ActiveSheet.Paste
Sheets("Financing").Select
ActiveWindow.SmallScroll Down:=42
Rows("89:89").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Rows("97:97").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=-45
Rows("24:24").Select
Selection.Insert Shift:=xlDown
Range("F23").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("F24").Select
ActiveSheet.Paste
Range("A24:E24").Select
Range("E24").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=54
Range("F98").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=96
Rows("187:187").Select
Selection.Insert Shift:=xlDown
Rows("194:194").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=-57
Rows("121:121").Select
Selection.Insert Shift:=xlDown
Range("F120").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("F121").Select
ActiveSheet.Paste
Range("A121:E121").Select
Range("E121").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=57
Range("F195").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=99
Rows("285:285").Select
Selection.Insert Shift:=xlDown
Rows("291:291").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=-51
Rows("218:218").Select
Selection.Insert Shift:=xlDown
Range("F217").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("F218").Select
ActiveSheet.Paste
Range("A218:E218").Select
Range("E218").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=54
Range("F292").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=87
Rows("383:383").Select
Selection.Insert Shift:=xlDown
Rows("388:388").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=-48
Rows("315:315").Select
Selection.Insert Shift:=xlDown
Range("F314").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("F315").Select
ActiveSheet.Paste
Range("A315:E315").Select
Range("E315").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=54
Range("F389").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=96
Rows("481:481").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=9
Rows("493:493").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=-63
Rows("412:412").Select
Selection.Insert Shift:=xlDown
Range("F411").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("F412").Select
ActiveSheet.Paste
Range("A412:E412").Select
Range("E412").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=60
Range("F489").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=-171
ActiveWindow.ScrollRow = 276
ActiveWindow.ScrollRow = 274
ActiveWindow.ScrollRow = 272
ActiveWindow.ScrollRow = 271
ActiveWindow.ScrollRow = 269
ActiveWindow.ScrollRow = 267
ActiveWindow.ScrollRow = 265
ActiveWindow.ScrollRow = 264
ActiveWindow.ScrollRow = 262
ActiveWindow.ScrollRow = 260
ActiveWindow.ScrollRow = 258
ActiveWindow.ScrollRow = 257
ActiveWindow.ScrollRow = 255
ActiveWindow.ScrollRow = 252
ActiveWindow.ScrollRow = 248
ActiveWindow.ScrollRow = 245
ActiveWindow.ScrollRow = 242
ActiveWindow.ScrollRow = 240
ActiveWindow.ScrollRow = 236
ActiveWindow.ScrollRow = 233
ActiveWindow.ScrollRow = 230
ActiveWindow.ScrollRow = 228
ActiveWindow.ScrollRow = 225
ActiveWindow.ScrollRow = 223
ActiveWindow.ScrollRow = 222
ActiveWindow.ScrollRow = 219
ActiveWindow.ScrollRow = 218
ActiveWindow.ScrollRow = 216
ActiveWindow.ScrollRow = 215
ActiveWindow.ScrollRow = 213
ActiveWindow.ScrollRow = 212
ActiveWindow.ScrollRow = 210
ActiveWindow.ScrollRow = 208
ActiveWindow.ScrollRow = 207
ActiveWindow.ScrollRow = 206
ActiveWindow.ScrollRow = 204
ActiveWindow.ScrollRow = 202
ActiveWindow.ScrollRow = 199
ActiveWindow.ScrollRow = 198
ActiveWindow.ScrollRow = 197
ActiveWindow.ScrollRow = 194
ActiveWindow.ScrollRow = 192
ActiveWindow.ScrollRow = 189
ActiveWindow.ScrollRow = 187
ActiveWindow.ScrollRow = 186
ActiveWindow.ScrollRow = 182
ActiveWindow.ScrollRow = 179
ActiveWindow.ScrollRow = 175
ActiveWindow.ScrollRow = 172
ActiveWindow.ScrollRow = 168
ActiveWindow.ScrollRow = 162
ActiveWindow.ScrollRow = 155
ActiveWindow.ScrollRow = 153
ActiveWindow.ScrollRow = 148
ActiveWindow.ScrollRow = 145
ActiveWindow.ScrollRow = 143
ActiveWindow.ScrollRow = 138
ActiveWindow.ScrollRow = 136
ActiveWindow.ScrollRow = 133
ActiveWindow.ScrollRow = 129
ActiveWindow.ScrollRow = 124
ActiveWindow.ScrollRow = 121
ActiveWindow.ScrollRow = 117
ActiveWindow.ScrollRow = 114
ActiveWindow.ScrollRow = 112
ActiveWindow.ScrollRow = 109
ActiveWindow.ScrollRow = 107
ActiveWindow.ScrollRow = 105
ActiveWindow.ScrollRow = 104
ActiveWindow.ScrollRow = 102
ActiveWindow.ScrollRow = 100
ActiveWindow.ScrollRow = 98
ActiveWindow.ScrollRow = 96
ActiveWindow.ScrollRow = 95
ActiveWindow.ScrollRow = 94
ActiveWindow.ScrollRow = 92
ActiveWindow.ScrollRow = 90
ActiveWindow.ScrollRow = 89
ActiveWindow.ScrollRow = 87
ActiveWindow.ScrollRow = 85
ActiveWindow.ScrollRow = 83
ActiveWindow.ScrollRow = 82
ActiveWindow.ScrollRow = 80
ActiveWindow.ScrollRow = 77
ActiveWindow.ScrollRow = 75
ActiveWindow.ScrollRow = 74
ActiveWindow.ScrollRow = 70
ActiveWindow.ScrollRow = 66
ActiveWindow.ScrollRow = 63
ActiveWindow.ScrollRow = 60
ActiveWindow.ScrollRow = 58
ActiveWindow.ScrollRow = 55
ActiveWindow.ScrollRow = 51
ActiveWindow.ScrollRow = 48
ActiveWindow.ScrollRow = 46
ActiveWindow.ScrollRow = 43
ActiveWindow.ScrollRow = 40
ActiveWindow.ScrollRow = 38
ActiveWindow.ScrollRow = 35
ActiveWindow.ScrollRow = 34
ActiveWindow.ScrollRow = 32
ActiveWindow.ScrollRow = 30
ActiveWindow.ScrollRow = 28
ActiveWindow.ScrollRow = 26
ActiveWindow.ScrollRow = 25
ActiveWindow.ScrollRow = 24
ActiveWindow.ScrollRow = 23
ActiveWindow.ScrollRow = 22
ActiveWindow.ScrollRow = 21
ActiveWindow.ScrollRow = 19
ActiveWindow.ScrollRow = 17
ActiveWindow.ScrollRow = 16
ActiveWindow.ScrollRow = 15
ActiveWindow.ScrollRow = 14
ActiveWindow.ScrollRow = 13
ActiveWindow.ScrollRow = 12
ActiveWindow.ScrollRow = 11
ActiveWindow.ScrollRow = 10
ActiveWindow.ScrollRow = 9
ActiveWindow.ScrollRow = 8
ActiveWindow.ScrollRow = 7
ActiveWindow.ScrollRow = 5
ActiveWindow.ScrollRow = 4
ActiveWindow.ScrollRow = 3
ActiveWindow.ScrollRow = 2
ActiveWindow.ScrollRow = 1
Sheets("Project Costs").Select
Range("B30").Select
End Sub
create a macro that would insert a new line into a project cost
catagory. This line would then need to be inserted throughout the
rest of the model to be referenced. I have created a step by step
recorded macro as to the functionality and formating changes needed as
the new line item is placed throughout the workbook. The problem
occurs when selecting the bottom of a set catagory of costs. Instead
of referencing the bottom of the set each time the macro is run, it
continually inserts the line item on a specific row number. I do not
have enough knowledge of VBA and would appreciate any help that could
shed some light on fixing this problem. Below is a copy of the VBA
code of the recorded step by step macro.
Sub LandDevelopCostsAdd()
'
' LandDevelopCostsAdd Macro
' Macro recorded 3/20/2007 by wperkins
'
'
Rows("30:30").Select
Selection.Insert Shift:=xlDown
Rows("29:29").Select
Selection.Copy
Rows("30:30").Select
ActiveSheet.Paste
Sheets("Financing").Select
ActiveWindow.SmallScroll Down:=42
Rows("89:89").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Rows("97:97").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=-45
Rows("24:24").Select
Selection.Insert Shift:=xlDown
Range("F23").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("F24").Select
ActiveSheet.Paste
Range("A24:E24").Select
Range("E24").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=54
Range("F98").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=96
Rows("187:187").Select
Selection.Insert Shift:=xlDown
Rows("194:194").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=-57
Rows("121:121").Select
Selection.Insert Shift:=xlDown
Range("F120").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("F121").Select
ActiveSheet.Paste
Range("A121:E121").Select
Range("E121").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=57
Range("F195").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=99
Rows("285:285").Select
Selection.Insert Shift:=xlDown
Rows("291:291").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=-51
Rows("218:218").Select
Selection.Insert Shift:=xlDown
Range("F217").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("F218").Select
ActiveSheet.Paste
Range("A218:E218").Select
Range("E218").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=54
Range("F292").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=87
Rows("383:383").Select
Selection.Insert Shift:=xlDown
Rows("388:388").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=-48
Rows("315:315").Select
Selection.Insert Shift:=xlDown
Range("F314").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("F315").Select
ActiveSheet.Paste
Range("A315:E315").Select
Range("E315").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=54
Range("F389").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=96
Rows("481:481").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=9
Rows("493:493").Select
Selection.Insert Shift:=xlDown
ActiveWindow.SmallScroll Down:=-63
Rows("412:412").Select
Selection.Insert Shift:=xlDown
Range("F411").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("F412").Select
ActiveSheet.Paste
Range("A412:E412").Select
Range("E412").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=60
Range("F489").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=-171
ActiveWindow.ScrollRow = 276
ActiveWindow.ScrollRow = 274
ActiveWindow.ScrollRow = 272
ActiveWindow.ScrollRow = 271
ActiveWindow.ScrollRow = 269
ActiveWindow.ScrollRow = 267
ActiveWindow.ScrollRow = 265
ActiveWindow.ScrollRow = 264
ActiveWindow.ScrollRow = 262
ActiveWindow.ScrollRow = 260
ActiveWindow.ScrollRow = 258
ActiveWindow.ScrollRow = 257
ActiveWindow.ScrollRow = 255
ActiveWindow.ScrollRow = 252
ActiveWindow.ScrollRow = 248
ActiveWindow.ScrollRow = 245
ActiveWindow.ScrollRow = 242
ActiveWindow.ScrollRow = 240
ActiveWindow.ScrollRow = 236
ActiveWindow.ScrollRow = 233
ActiveWindow.ScrollRow = 230
ActiveWindow.ScrollRow = 228
ActiveWindow.ScrollRow = 225
ActiveWindow.ScrollRow = 223
ActiveWindow.ScrollRow = 222
ActiveWindow.ScrollRow = 219
ActiveWindow.ScrollRow = 218
ActiveWindow.ScrollRow = 216
ActiveWindow.ScrollRow = 215
ActiveWindow.ScrollRow = 213
ActiveWindow.ScrollRow = 212
ActiveWindow.ScrollRow = 210
ActiveWindow.ScrollRow = 208
ActiveWindow.ScrollRow = 207
ActiveWindow.ScrollRow = 206
ActiveWindow.ScrollRow = 204
ActiveWindow.ScrollRow = 202
ActiveWindow.ScrollRow = 199
ActiveWindow.ScrollRow = 198
ActiveWindow.ScrollRow = 197
ActiveWindow.ScrollRow = 194
ActiveWindow.ScrollRow = 192
ActiveWindow.ScrollRow = 189
ActiveWindow.ScrollRow = 187
ActiveWindow.ScrollRow = 186
ActiveWindow.ScrollRow = 182
ActiveWindow.ScrollRow = 179
ActiveWindow.ScrollRow = 175
ActiveWindow.ScrollRow = 172
ActiveWindow.ScrollRow = 168
ActiveWindow.ScrollRow = 162
ActiveWindow.ScrollRow = 155
ActiveWindow.ScrollRow = 153
ActiveWindow.ScrollRow = 148
ActiveWindow.ScrollRow = 145
ActiveWindow.ScrollRow = 143
ActiveWindow.ScrollRow = 138
ActiveWindow.ScrollRow = 136
ActiveWindow.ScrollRow = 133
ActiveWindow.ScrollRow = 129
ActiveWindow.ScrollRow = 124
ActiveWindow.ScrollRow = 121
ActiveWindow.ScrollRow = 117
ActiveWindow.ScrollRow = 114
ActiveWindow.ScrollRow = 112
ActiveWindow.ScrollRow = 109
ActiveWindow.ScrollRow = 107
ActiveWindow.ScrollRow = 105
ActiveWindow.ScrollRow = 104
ActiveWindow.ScrollRow = 102
ActiveWindow.ScrollRow = 100
ActiveWindow.ScrollRow = 98
ActiveWindow.ScrollRow = 96
ActiveWindow.ScrollRow = 95
ActiveWindow.ScrollRow = 94
ActiveWindow.ScrollRow = 92
ActiveWindow.ScrollRow = 90
ActiveWindow.ScrollRow = 89
ActiveWindow.ScrollRow = 87
ActiveWindow.ScrollRow = 85
ActiveWindow.ScrollRow = 83
ActiveWindow.ScrollRow = 82
ActiveWindow.ScrollRow = 80
ActiveWindow.ScrollRow = 77
ActiveWindow.ScrollRow = 75
ActiveWindow.ScrollRow = 74
ActiveWindow.ScrollRow = 70
ActiveWindow.ScrollRow = 66
ActiveWindow.ScrollRow = 63
ActiveWindow.ScrollRow = 60
ActiveWindow.ScrollRow = 58
ActiveWindow.ScrollRow = 55
ActiveWindow.ScrollRow = 51
ActiveWindow.ScrollRow = 48
ActiveWindow.ScrollRow = 46
ActiveWindow.ScrollRow = 43
ActiveWindow.ScrollRow = 40
ActiveWindow.ScrollRow = 38
ActiveWindow.ScrollRow = 35
ActiveWindow.ScrollRow = 34
ActiveWindow.ScrollRow = 32
ActiveWindow.ScrollRow = 30
ActiveWindow.ScrollRow = 28
ActiveWindow.ScrollRow = 26
ActiveWindow.ScrollRow = 25
ActiveWindow.ScrollRow = 24
ActiveWindow.ScrollRow = 23
ActiveWindow.ScrollRow = 22
ActiveWindow.ScrollRow = 21
ActiveWindow.ScrollRow = 19
ActiveWindow.ScrollRow = 17
ActiveWindow.ScrollRow = 16
ActiveWindow.ScrollRow = 15
ActiveWindow.ScrollRow = 14
ActiveWindow.ScrollRow = 13
ActiveWindow.ScrollRow = 12
ActiveWindow.ScrollRow = 11
ActiveWindow.ScrollRow = 10
ActiveWindow.ScrollRow = 9
ActiveWindow.ScrollRow = 8
ActiveWindow.ScrollRow = 7
ActiveWindow.ScrollRow = 5
ActiveWindow.ScrollRow = 4
ActiveWindow.ScrollRow = 3
ActiveWindow.ScrollRow = 2
ActiveWindow.ScrollRow = 1
Sheets("Project Costs").Select
Range("B30").Select
End Sub