Auto_Open() and OnEntry Problem - please help!
Posted by Artem on March 08, 2001 9:46 PM
Hello,
I would be very gratefull if anyone could help me with my problem.
I'm trying to create a macro which would run after a cell entry has been changed. Specifically, after i change a cell I want
the macro to take the previous (old) input of the active cell as string, then do Replace all the occurences of this string in
a current active row with the new input string. For example if I have a row with the following entries from A1 to E1 (i use |
to show separate cells):
| ZZZZ | ABSZZZZ | ='C:\Docs\[ZZZZ.xls]Sheet1'!$E$6 | SMTH | ZZZZ
Then if I change the first cell to smth. like AAAA, i want the row to be like this:
| AAAA | ABSAAAA | ='C:\Docs\[AAAA.xls]Sheet1'!$E$6 | SMTH | AAAA
And I want to be able to do it for multiple rows.
Unfortunately, my two-day VBA experience didn't help me much. The only thing i could write is for the macro to change
predefined entries in a row with a new input, i.e. it would change all occurencies of a certain word in an active row, but
unfortunately i couldn't make that "certain word" to be a old cell entry. Here's what i have so far (this has extensive
copy-pasting from examples off the web).
Sub Auto_Open()
ThisWorkbook.Worksheets("Sheet1").OnEntry = "DidCellsChange"
End Sub
-------------------------------------------------------------------
Sub DidCellsChange()
Dim KeyCells As String
KeyCells = "A1:A5"
' If the Activecell is one of the key cells, call the
' ReplaceEntireRow macro.
If Not Application.Intersect(ActiveCell, Range(KeyCells)) _
Is Nothing Then ReplaceEntireRow
End Sub
-------------------------------------------------------------------
Sub ReplaceEntireRow()
Dim NewWord As String
NewWord = ActiveCell.Value
ActiveCell.EntireRow.Replace What:="AAAA", Replacement:=NewWord, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
End Sub
As you see this will only replace AAAA occurencies in an active row, not the old entry occurencies. So this is my problem.
Thank you very much for your help!