Combine two sets of code into one

I have two sets of code called "Sort" and "SortMain" that I would like combined into one, this way when I click on a button it will take care of both at the same time.  Please see the following:

Sub Sort()
With Worksheets("MAIN_PN").Range("A4:M650")
    .NumberFormat = "@"
    .Value = .Value
End With
End Sub

Sub SortMain()
With Worksheets("MAIN").Range("C26:W30")
    .NumberFormat = "@"
    .Value = .Value
End With
End Sub
LUIS FREUNDAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Hi Luis,

Please try this...
Sub SortBothSheets()
With Worksheets("MAIN_PN").Range("A4:M650")
    .NumberFormat = "@"
    .Value = .Value
End With

With Worksheets("MAIN").Range("C26:W30")
    .NumberFormat = "@"
    .Value = .Value
End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
Or just

Sub SortBothSheets()
Sort
SortMain
End Sub

Open in new window

0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
@Martin

What's the point in having three codes? Why not have both the codes into a single code as I suggested?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Martin LissOlder than dirtCommented:
There's nothing wrong with the way you did it, however there's nothing wrong with keeping the existing subs in case the Author might someday want to do just one of them.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
That's hypothetical case Martin. Luis is aware of what he asked. :)
Never mind. :)
0
LUIS FREUNDAuthor Commented:
Thanks Gents!  Exactly what I need Neeraj
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Luis! Glad I could help.
0
LUIS FREUNDAuthor Commented:
I posted another question along the same concept that you provided once before....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.