I have found the easiest way to do anyhting like this is to record a macro whilst manually performing the operation you require. Then look at the code produced, and edit where necessary.
Usually, the resultant VBA is a bit over-the-top. It will contain a whole load of stuff that is actually not required. But you can remove this manually to get more compact code. Comment it out first, make sure it still works correctly, then delete it.