B
Bill Hertzing
I need to iterate over a row of cells, and if the value matches
string1, replace it with string2. There's no inherent ordering.
I found that with a class called ReplaceColumnTitle which has two
properties oldstring and replacementstring, and a collection
CollReplaceColumnTitle, I can easily iterate over each
ReplaceColumnTitle in the CollReplaceColumnTitle, test the cell value
against each oldstring and replace it if it matchs.
I don't see any 'good' way to encapuslate all the
oldstring/replacementstring pairs (there are about 30, and growing)
for populating the collection CollReplaceColumnTitle. I know XML is
probably perfect for this, but the learning curve for adding XML
programming to Excel macros using VBA is too costly for my immediate
needs, I think.
one way I've considered is to create a collection class, and to add
the name/value pairs to the collection during Class_Initialize. That
lets me isolate the information into the class module. I've tried to
do this, but:
How do I tell VBA that the new class is a collection?
How do I refer to 'myself' within the Class_Initialize subroutine?
Example:
Private Sub Class_Initialize()
Dim acr As ReplaceColumnTitle
Set acr = New ReplaceColumnTitle
acr.OS = "Transport Service CPU"
acr.RS = TransportCPUPM
Me.Add acr
end sub
I've tried Me.Add, This.add, .Add - nope on any of them.
Thanks for any suggestions, especially big-picture ones that offer a
good way to encapsulate the name/value pairs!
string1, replace it with string2. There's no inherent ordering.
I found that with a class called ReplaceColumnTitle which has two
properties oldstring and replacementstring, and a collection
CollReplaceColumnTitle, I can easily iterate over each
ReplaceColumnTitle in the CollReplaceColumnTitle, test the cell value
against each oldstring and replace it if it matchs.
I don't see any 'good' way to encapuslate all the
oldstring/replacementstring pairs (there are about 30, and growing)
for populating the collection CollReplaceColumnTitle. I know XML is
probably perfect for this, but the learning curve for adding XML
programming to Excel macros using VBA is too costly for my immediate
needs, I think.
one way I've considered is to create a collection class, and to add
the name/value pairs to the collection during Class_Initialize. That
lets me isolate the information into the class module. I've tried to
do this, but:
How do I tell VBA that the new class is a collection?
How do I refer to 'myself' within the Class_Initialize subroutine?
Example:
Private Sub Class_Initialize()
Dim acr As ReplaceColumnTitle
Set acr = New ReplaceColumnTitle
acr.OS = "Transport Service CPU"
acr.RS = TransportCPUPM
Me.Add acr
end sub
I've tried Me.Add, This.add, .Add - nope on any of them.
Thanks for any suggestions, especially big-picture ones that offer a
good way to encapsulate the name/value pairs!