Link to home
Start Free TrialLog in
Avatar of Pancake_Effect
Pancake_EffectFlag for United States of America

asked on

Excel: Copy Column to another macro

I have a long macro I'm running for a user here at work. I'm wanting to insert in the middle of it a macro, a part that copies the entire column of D over to Q.

Essentially I just want D to = Q.

Problem is with a simple formula such as =D2 leaves zero's if there is nothing there in D that goes on forever.

So I see a macro as a better solution, also because the user can just hit run on the macro and change it all over all at once besides running the macro, then making sure the formulas work.


Just so you an see my already made macro I'll attach it. It's current functions have nothing to do with this one. If I can just insert it in there, that would be great rather than worry about two macros.
MACRO.txt
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pancake_Effect

ASKER

Worked great! Thank you so much.

-I know there probably a better way, I've been Frankenstein'ing it with pieces I've been gathering pretty much entirely by the help by the expert exchange community. (Thank god for expert exchange) I have no idea how any of this works, I'm trying to learn however, specially after building this, I've been looking at each piece and trying to learn it.

I'm actually just a network guy, trying to learn this for a user, since I'm the only IT guy up here, it lands on me haha.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeh I was talking about the Select case thing, (the copy worked great)

I see what your doing, I'll give it a try when I get a moment, thanks for the tip!
Avatar of Norie
Norie

Do you have a list of all these old values and their new values?

If you did, or could create/get one, then you could get rid of the Select Case altogether.

What you would use in it's place would be a VLOOKUP which you can use in the code via Application.WorksheetFunction.
Yeh I was given copy of 6 pages of medical codes along with the numbers associated with each one. What I did was, as you can see,  was I just typed in each one for each column.

Essentially they have a program that spits out the raw data onto excel, but we recently merged with another company and they require it to be in a completely different format. (There's no way to change the initial raw format.) Hence why I have to do all these changes via macros.
As for that giant Select Case block, "better ways" could include matched-index arrays with one having the original values and the other matching target values for each, a collection of structs doing pretty much the same thing (though you could save on memory there by having objects in the collection contain more than one value for the same target), or reading directly from a worksheet or other data source. You'd then loop over stuff or choose by index or whatever suits the types you're using.

Whether those are actually "better", though, depends entirely on the goal and the context. Looping through a collection could be much slower, especially if you end up nesting loop within loop and not having any way to exit once you've found a match. However, they also allow much more flexibility in the matching parameters, up to and possibly including (depending on how you go about it) regular expressions.
Thanks for the help!