Calling a Sub within the Main Macro

BrittKnee

New Member
Joined
Dec 4, 2017
Messages
20
I am having issues with this string of code:

Sub Format_Workbook_Pt2()

Sub ConvertTextToNumber()
Sheets("All_Data").Select
Range("C:C").Select
Selection.TextToColumns _
Destination:=Range("A:A"), _
DataType:=xlDelimited
End Sub
End Sub


I wanted to keep Sub Frmat_Worbook_Pt2() as the main macro as I build more code into the main macro.
Thanks!
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,509
Office Version
365
Platform
Windows
You need to do it like
Code:
Sub Format_Workbook_Pt2()
   Call ConvertTextToNumber
End Sub
Sub ConvertTextToNumber()
Sheets("All_Data").Select
Range("C:C").Select
Selection.TextToColumns _
Destination:=Range("A:A"), _
DataType:=xlDelimited
End Sub
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
52,066
Office Version
365
Platform
Windows
You CANNOT imbed one macro inside another. They would be two separate macros, and you would just call one from the other:
Code:
[COLOR=#333333]Sub Format_Workbook_Pt2()[/COLOR]
[B]    [COLOR=#0000ff]Call ConvertTextToNumber[/COLOR][/B]
End Sub

[COLOR=#333333]Sub ConvertTextToNumber()[/COLOR]
[COLOR=#333333]    Sheets("All_Data").Select[/COLOR]
[COLOR=#333333]    Range("C:C").Select[/COLOR]
[COLOR=#333333]    Selection.TextToColumns _[/COLOR]
[COLOR=#333333]    Destination:=Range("A:A"), _[/COLOR]
[COLOR=#333333]    DataType:=xlDelimited[/COLOR]
[COLOR=#333333]End Sub[/COLOR]
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,509
Office Version
365
Platform
Windows
Glad we could help & thanks for the feedback
 

Forum statistics

Threads
1,089,203
Messages
5,406,817
Members
403,108
Latest member
alyb

This Week's Hot Topics

Top