Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
547 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Posted by Andrew Gould on 25 July 2021
This video shows you how to split a single Eacel table into multiple worksheets using the values in a column of the table. You'll learn how to create a recordset and populate it with unique values from a column and how to create a SELECT INTO command to create new worksheets. You'll see how to create new worksheets in the same workbook as the source data, in a single different workbook and how to create a separate workbook for each value in the column.
See our full range of VBA training resources, or test your knowledge of VBA with one of our VBA skills assessment tests.
This video has the following accompanying files:
File name | Type | Description |
---|---|---|
Split Table into Separate Sheets.xlsm | Excel workbook with macros | The code |
Movies.xlsx | Excel workbook | The source data |
Click to download a zipped copy of the above files.
There are no exercises for this video.
You can increase the size of your video to make it fill the screen like this:
Play your video (the icons shown won't appear until you do), then click on the full screen icon which appears as shown above.
When you've finished viewing a video in full screen mode, just press the Esc key to return to normal view.
To improve the quality of a video, first click on the Settings icon:
Make sure yoiu're playing your video so that the icons shown above appear, then click on this gear icon.
Choose to change the video quality:
Click as above to change your video quality.
The higher the number you choose, the better will be your video quality (but the slower the connection speed):
Don't choose the HD option shown unless your connection speed is fast enough to support it!
Is your Wise Owl speaking too slowly (or too quickly)? You can also use the Settings menu above to change your playback speed.
From: | Chandra |
When: | 22 Oct 21 at 14:15 |
I am unable to create files in Path, I am getting runtime error, please see the below code
Sub SplitTable()
Dim MovieFilePath As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
MovieFilePath = ThisWorkbook.Path & "\Movies.xlsx"
Set cn = New ADODB.Connection
cn.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & MovieFilePath & ";" & _
"Extended Properties='Excel 12.0 Xml;HDR=YES';"
cn.Open
Set rs = New ADODB.Recordset
rs.ActiveConnection = cn
rs.Source = " Select DISTINCT [Country] From [Film$] "
rs.Open
Set cmd = New ADODB.Command
cmd.ActiveConnection = cn
cmd.CommandType = adCmdText
Do Until rs.EOF
' Debug.Print rs.Fields("Country").Value
cmd.CommandText = _
" Select * " & _
" Into [" & rs.Fields("Country").Value & "]" & _
" In ' " & ThisWorkbook.Path & " \ Countries Data \ " & rs.Fields("Country").Value & " .xlsx' 'Excel 12.0 Xml; ' " & _
" From [Film$] " & _
" Where [Country]= ' " & rs.Fields("Country").Value & " ' "
' Debug.Print cmd.CommandText
cmd.Execute
rs.MoveNext
Loop
rs.Close
cn.Close
End Sub
From: | Andrew G |
When: | 22 Oct 21 at 14:36 |
I would guess that you've included too many additional spaces in this part of your code
ThisWorkbook.Path & " \ Countries Data \ " & rs.Fields("Country").Value & " .xlsx' 'Excel 12.0 Xml; ' "
Unless your folder names and file names actually have those spaces I would remove them so that it looks more like this
ThisWorkbook.Path & "\Countries Data\" & rs.Fields("Country").Value & ".xlsx' 'Excel 12.0 Xml;'"
I hope it helps!
From: | Chandra |
When: | 26 Oct 21 at 12:12 |
I remove extra specs Inside the code, after that I am getting runtime error below :
RUN TIME Error -2147217900(80040e14)
invalid bracketing of name ' i;\fileneeded-31\All\Australia.xlsx'
i have mentioned code below:
cmd.CommandText = _
" Select * " & _
" Into [" & rs.Fields("Country").Value & "]" & _
" In ' " & ThisWorkbook.Path & "\All\" & rs.Fields("Country").Value & ".xlsx' 'Excel 12.0 Xml;'" & _
" From [Film$] " & _
" Where [Country]= ' " & rs.Fields("Country").Value & " ' "
From: | Andrew G |
When: | 29 Oct 21 at 07:40 |
Hi there! If you perform a Google search for "clear cached files google chrome" it will explain how to do this. You can then download the file containing the CompletedCode module from this page. I hope it helps!
From: | Chandra |
When: | 29 Oct 21 at 07:27 |
I am unable to Understand, please try to explain, I have two browsers one is Google Chrome and another one Microsoft Edge.
From: | Andrew G |
When: | 27 Oct 21 at 14:21 |
Try clearing your browser's cached files.
From: | Chandra |
When: | 27 Oct 21 at 11:30 |
Again I have downloaded the file , in that file there is no code,
in that file this code is there
Sub SplitTable()
Dim MovieFilePath As String
Dim cn As ADODB.Connection
MovieFilePath = ThisWorkbook.Path & "\Movies.xlsx"
Set cn = New ADODB.Connection
cn.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & MovieFilePath & ";" & _
"Extended Properties='Excel 12.0 Xml;HDR=YES';"
cn.Open
cn.Close
End Sub
From: | Andrew G |
When: | 27 Oct 21 at 07:57 |
The example file now contains a module called "Completed code". I hope it helps.
From: | Chandra |
When: | 27 Oct 21 at 06:57 |
Hi
I downloaded the file, in that file there is no code, if You possible please share me the file
From: | Andrew G |
When: | 26 Oct 21 at 16:04 |
Hi, I would recommend downloading the example file from this page and comparing your code very carefully to the working example in that file.
From: | Pssaba |
When: | 20 Aug 21 at 16:26 |
Hello Andrew:
I was wondering if you will be posting more videos on SQL for Excel. The information has been very useful to me and has saved me a lot of programming that otherwise I would have to do with VBA. If not, do you have any links to websites that specifically deal with this version of SQL for Excel? I note that a lot of features of SQL are not applicable to that version (e.g. unable to do full joins).
From: | Andrew G |
When: | 22 Aug 21 at 07:45 |
Hi, I'm happy to hear that you've found the SQL for Excel series of videos useful!
There are a few extra topics on my list to cover, but these are things that are more to do with the ADO side of things than with SQL. I think that the existing 31 videos already cover the broad strokes of what this version of SQL is capable of but for further reading I'd recommend searching for "Access SQL".
I hope that helps and thanks for watching!
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.