Combine two sets of code into one

LUIS FREUND
LUIS FREUND used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015
Commented:
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

Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Or just

Sub SortBothSheets()
Sort
SortMain
End Sub

Open in new window

Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
@Martin

What's the point in having three codes? Why not have both the codes into a single code as I suggested?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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.
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
That's hypothetical case Martin. Luis is aware of what he asked. :)
Never mind. :)

Author

Commented:
Thanks Gents!  Exactly what I need Neeraj
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
You're welcome Luis! Glad I could help.

Author

Commented:
I posted another question along the same concept that you provided once before....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial