This can work but is highly circumstantial
In essence I agree with @SevenSidedDie's answer@SevenSidedDie's answer that you must be hidden when you make the attack, however, there is a nuance in the rule on hiding in combat that is being overlooked:
In combat, most creatures stay alert for signs of danger all around, so if you come out of hiding and approach a creature, it usually sees you.
If you come out of hiding and do not approach, say by making a ranged attack, you should get the advantage and all the benefits that flow therefrom. There is a world of difference from knowing the rogue is hiding behind the column and being aware of the exact moment they step out and flick a dagger at you. To rule otherwise is to give the words "and approach" no work to do in the sentence above.