Welcome to the forum. Whenever I am stuck with a problem like this and I dont know the code right off the top of my head, I usually turn on the macro recorder and execute the steps that I need to write code for. The steps you describe should come up fine in the macro recorder. The resulting code can be found in a standard module in the VBE editor.
If youre still having problems with the code the macro recorder produced, post back your results and let us know how we can help further.