Lets say I contributed $18,000 to my 401(k) this year, and my employer matched 50%, so I have a total of $27,000 contributed this year. This money I invested and made $1000, so now I have $28,000. At this point, however, I realized I originally wanted to contribute to my Roth 401(k) and not my 401(k). Is there a way to "roll over" this contribution so I pay taxes on the $27,000, or would I have to pay taxes on the $28,000?
This is called an in-plan Roth conversion and is discussed by the IRS here. If your 401(k) has a Roth option then it likely also has a provision to convert pre-tax dollars, but you'll have to check with the administrator to be sure. They could also potentially limit the type of money that can be converted. But most likely you should be able to convert any amount you want, and since it's all pre-tax (your contributions, employer matching, and earnings), it doesn't really matter which money is converted because it's all equivalent. One caveat is you won't able to convert any employer matching that hasn't fully vested.