Automatically copy data from main sheet to child sheets.
Solved/Closed
Fenrir91_9
Posts
4
Registration date
Tuesday February 26, 2019
Status
Member
Last seen
October 10, 2019
-
Updated on Feb 28, 2019 at 05:38 AM
vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 - Mar 1, 2019 at 01:00 AM
vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 - Mar 1, 2019 at 01:00 AM
Related:
- Automatically copy data from main sheet to child sheets.
- Google sheet right to left - Guide
- Transfer data from one excel worksheet to another automatically - Guide
- Windows network commands cheat sheet - Guide
- Mark sheet in excel - Guide
- Little alchemy cheat sheet - Guide
2 responses
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
Feb 27, 2019 at 09:44 PM
Feb 27, 2019 at 09:44 PM
Hello Fenrir,
That error generally means that a sheet doesn't exist or can't be found (due to things such as incorrect spelling, additional spaces etc.).
For example, in your code above, this line:-
suggests that you are trying to find/extract sixteen characters from the right hand side of a cell value to use as criteria.The question here is: Is there sixteen characters that you need to find?
For us to endeavour to help you, it would be a good idea for you to upload a sample of your workbook to a free file sharing site (such as GE.TT or Drop Box) and then post the link to your sample file back here.
Make sure that the sample is an exact replica of your actual workbook and if your data is sensitive then please use dummy data.
Cheerio,
vcoolio.
That error generally means that a sheet doesn't exist or can't be found (due to things such as incorrect spelling, additional spaces etc.).
For example, in your code above, this line:-
Text = Right(rng.Value, 16)
suggests that you are trying to find/extract sixteen characters from the right hand side of a cell value to use as criteria.The question here is: Is there sixteen characters that you need to find?
For us to endeavour to help you, it would be a good idea for you to upload a sample of your workbook to a free file sharing site (such as GE.TT or Drop Box) and then post the link to your sample file back here.
Make sure that the sample is an exact replica of your actual workbook and if your data is sensitive then please use dummy data.
Cheerio,
vcoolio.
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
Feb 28, 2019 at 05:29 AM
Feb 28, 2019 at 05:29 AM
Hello Fenrir,
Following is a code that should do the task for you:-
To further automate the whole process and, in effect, simplify it a little, I've actually taken this one step further for you.
The code actually creates the required worksheets for you as needed and transfers the relevant data to the relevant sheet.
The code places a formula in a helper column (Column P) which extracts the month from Column G and adds "Expire" in front of the relevant month (e.g. Expire 06) which thus creates your sheet names (as per your sample). Line 15 in the code above shows the formula that is used.
Hence, as you add new dates with differing months, new sheets will be added as required without duplication. The data in each sheet is refreshed each time the code is executed.
To further streamline the code and speed it up even more, the data in the "Customer List" sheet is sorted via Column P also.
Column P is always cleared and is only used for an instant as the helper.
Following is the link to your sample file with the code implemented:-
http://ge.tt/9hyzFju2
Click on the "RUN" button to see it work. You'll note that there aren't any individual month sheets when you open the file. These will be created on executing the code. Play around with the data in the Customer List sheet (add/delete) then click on the button again to see how each sheet is added/refreshed.
Hence, in your actual workbook, delete the existing month sheets and save the file without them. Just keep the Customer List and Data Summary sheets.
However, make sure that you test the code in a copy of your actual workbook first to satisfy yourself that all this works for you.
I hope that this helps.
Cheerio,
vcoolio.
Following is a code that should do the task for you:-
Sub CreateNewShtsTransferData() Dim sht As Worksheet, ws As Worksheet Dim lr As Long, x As Long Dim ID As Object Dim key As Variant Set sht = Sheet1 Set ID = CreateObject("Scripting.Dictionary") Application.ScreenUpdating = False lr = sht.Range("A" & Rows.Count).End(xlUp).Row sht.Range("P2:P" & lr) = "=""Expiry"" & "" "" & TEXT(G2,""mm"")" sht.Range("A2:P" & lr).Sort sht.[P2], 1 For x = 2 To lr If Not ID.Exists(sht.Range("P" & x).Value) Then ID.Add sht.Range("P" & x).Value, 1 End If Next x For Each key In ID.keys If Not Evaluate("ISREF('" & key & "'!A1)") Then Worksheets.Add(After:=Sheets(Sheets.Count)).Name = key End If Set ws = Sheets(key) ws.UsedRange.Clear sht.Range("P1:P" & lr).AutoFilter 1, key sht.[A1].CurrentRegion.Copy ws.[A1] ws.Columns.AutoFit sht.[P1].AutoFilter Next key sht.Select sht.Columns(16).Clear Application.ScreenUpdating = True MsgBox "All done!", vbExclamation End Sub
To further automate the whole process and, in effect, simplify it a little, I've actually taken this one step further for you.
The code actually creates the required worksheets for you as needed and transfers the relevant data to the relevant sheet.
The code places a formula in a helper column (Column P) which extracts the month from Column G and adds "Expire" in front of the relevant month (e.g. Expire 06) which thus creates your sheet names (as per your sample). Line 15 in the code above shows the formula that is used.
Hence, as you add new dates with differing months, new sheets will be added as required without duplication. The data in each sheet is refreshed each time the code is executed.
To further streamline the code and speed it up even more, the data in the "Customer List" sheet is sorted via Column P also.
Column P is always cleared and is only used for an instant as the helper.
Following is the link to your sample file with the code implemented:-
http://ge.tt/9hyzFju2
Click on the "RUN" button to see it work. You'll note that there aren't any individual month sheets when you open the file. These will be created on executing the code. Play around with the data in the Customer List sheet (add/delete) then click on the button again to see how each sheet is added/refreshed.
Hence, in your actual workbook, delete the existing month sheets and save the file without them. Just keep the Customer List and Data Summary sheets.
However, make sure that you test the code in a copy of your actual workbook first to satisfy yourself that all this works for you.
I hope that this helps.
Cheerio,
vcoolio.
Fenrir91_9
Posts
4
Registration date
Tuesday February 26, 2019
Status
Member
Last seen
October 10, 2019
Feb 28, 2019 at 11:25 PM
Feb 28, 2019 at 11:25 PM
Hi Vcoolio,
Wow! Thank you so much! That is amazing and works perfectly! Can't thank you enough for your help! :)
Wow! Thank you so much! That is amazing and works perfectly! Can't thank you enough for your help! :)
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
Mar 1, 2019 at 01:00 AM
Mar 1, 2019 at 01:00 AM
You're welcome Fenrir. I'm glad to have been able to assist you.
Good luck with it all!
Cheerio,
vcoolio.
Good luck with it all!
Cheerio,
vcoolio.
Feb 27, 2019 at 10:48 PM
Thank you so much for your response!
I see my first error would certainly mess up the code. For the range, I was thinking that the "16" number would be telling the code how many columns over it can search for data, so I tried to give it a large range to search.
Here is a link to a dummy copy of the file on Dropbox.
https://www.dropbox.com/s/ieqka4l32srojrc/Expiring%20Warranty.xlsx?dl=0
I was hoping to get Excel to automatically copy the entire row of data into the corresponding monthly tab of when the warranty is expiring; for example, if the data of the customer on row 2 was just pasted into the excel then the entire row would be copied into the "Expire 09" tab based on the date in column G.
If the entire row is not possible to have it automatically copy, I can make do with just column B copying over and then I can set a Vlookup for the rest of the information from there.
Thank you again for your help!