Corrupted Macro
"Myrna Larson" wrote:
If you follow your new plan, to put the base FILENAME in column A, the
following macro should work for either the data sheet OR the summary sheet. In
the problem case that started all of this, the client name is Garcia, but the
name in column A would be the file name, GarciaL.
The macro just finds the last name in column A and saves it in a variable.
Then it copies the entire next-to-last row to the last row. Then it replaces
the OldName with the NewName that was saved before the copy.
Sub AddLineData() ' to add a row on data page OR summary page
Dim lr As Long
Dim NewName As String
Dim OldName As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'the new name must already have been entered in column A
'of the last row, but the rest of the row is blank
lr = Cells(Rows.Count, "A").End(xlUp).Row
NewName = Cells(lr, 1).Value 'save this because copy will wipe it out
'next line overwrites the new name, but it doesn't matter
'because we saved it above
Rows(lr - 1).Copy Rows(lr)
'replace the old name with the new name
OldName = Cells(lr - 1, 1).Value
Rows(lr).Replace What:=OldName, Replacement:=Newname, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Thank you! Thank you!! Thank you!!! It works beautifully. To stretch my luck, could you give me a modification of this macro which looks for (begins with) the name in A6 and continues copying as long as there is a name in Column A. This way I could copy and paste a list of names into Column A5 through A whatever. Then I could write formulas in Row 5 from B5 to whatever. Then hit the "name" button to begin and the macro would copy beginning at Row 6 until the end of names in Column A.
I really appreciate this. It is the next-to-final step in what I consider
to be a great system for manufactured home dealerships. There is one more
thing I need. If you aren't sorry you offered to help me by now, perhaps I
could ask one more thing after this one.
Thanks again,
Vince
|