Copy data from 1 workbook to another based on sheet tabs
Solved/Closed
bimmy80
Posts
6
Registration date
Saturday October 17, 2015
Status
Member
Last seen
November 19, 2015
-
Oct 18, 2015 at 03:53 AM
bimmy80 Posts 6 Registration date Saturday October 17, 2015 Status Member Last seen November 19, 2015 - Oct 23, 2015 at 10:11 PM
bimmy80 Posts 6 Registration date Saturday October 17, 2015 Status Member Last seen November 19, 2015 - Oct 23, 2015 at 10:11 PM
Related:
- Copy data from 1 workbook to another based on sheet tabs
- Fnaf 1 download pc - Download - Horror
- Tentacle locker 1 - Download - Adult games
- Fnia 1 - Download - Adult games
- Igi 1 download - Download - Shooters
- Poppy playtime chapter 1 download pc - Download - Horror
5 responses
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Oct 20, 2015 at 04:24 PM
Oct 20, 2015 at 04:24 PM
do you have any thing done yet ?
bimmy80
Posts
6
Registration date
Saturday October 17, 2015
Status
Member
Last seen
November 19, 2015
Oct 21, 2015 at 01:50 AM
Oct 21, 2015 at 01:50 AM
Hello,
I came across below code
What the code does is open up the master workbook, paste the data in one particular range and close the master workbook.
I'm looking for few additions to the above code, which I have mentioned above under - what the macro should do.
Any assistance will be greatly appreciated.
I came across below code
Sub TransferDataV2()
'transfer stuff from this workbook to workbook 2
Dim strPath2 As String
Dim wbkWorkbook1 As Workbook
Dim wbkWorkbook2 As Workbook
'define paths and filenames
strPath2 = "D:\Master.xlsx"
'open files
Set wbkWorkbook1 = ThisWorkbook
Set wbkWorkbook2 = Workbooks.Open(strPath2)
wbkWorkbook2.Worksheets("Sheet1").Range("A1:B3").Value = _
wbkWorkbook1.Worksheets("Sheet1").Range("A1:B3").Value
'close the workbook
wbkWorkbook2.Close (True)
End Sub
What the code does is open up the master workbook, paste the data in one particular range and close the master workbook.
I'm looking for few additions to the above code, which I have mentioned above under - what the macro should do.
Any assistance will be greatly appreciated.
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Oct 21, 2015 at 11:25 AM
Oct 21, 2015 at 11:25 AM
Here is some thing build on top on your code
Sub TransferDataV2()
'transfer stuff from this workbook to workbook 2
Dim strPath2 As String
Dim wbkWorkbook1 As Workbook
Dim wbkWorkbook2 As Workbook
Dim strTargetSheet As String
'define paths and filenames
strPath2 = "D:\Master.xlsx"
'open files
Set wbkWorkbook1 = ThisWorkbook
'getting the target sheet name.
strTargetSheet = InputBox("Enter the target sheet name", "Target Sheet ...")
strTargetSheet = Trim(strTargetSheet) 'remove any leading and trailing spaces
If (strTargetSheet = vbNullString) Then 'check if there is no data
msgbbox "No Name entered"
End 'terminate
End If
Set wbkWorkbook2 = Workbooks.Open(strPath2)
'check if cell A1 has any data on target sheet. Hopefully you have at least one cell that would be
'always populated. With this, it is checking is A1 is not null
If (wbkWorkbook2.Worksheets(strTargetSheet).Range("A1") <> "") Then
MsgBox "Data Already exists"
End
End If
wbkWorkbook2.Worksheets(strTargetSheet).Range("A1:C8").Value = _
wbkWorkbook1.Worksheets("Sheet1").Range("A1:C8").Value
wbkWorkbook2.Worksheets(strTargetSheet).Range("E1:N1500").Value = _
wbkWorkbook1.Worksheets("Sheet1").Range("E1:N1500").Value
'close the workbook
wbkWorkbook2.Close (True)
End Sub
bimmy80
Posts
6
Registration date
Saturday October 17, 2015
Status
Member
Last seen
November 19, 2015
Oct 21, 2015 at 02:36 PM
Oct 21, 2015 at 02:36 PM
Greetings rizvisa1,
First of all a big thank you for taking time to come up with the code.
I request your assistance with regards to below 2 points -
1) If data exists macro should prompt for a message box stating "data exists insert new sheet" and then opens the sheet specified and paste data in respective ranges.
2)Above code does not open specified sheet. I want macro to open the specified sheet and then paste the data
Note :
(if this makes any sense)
Point 1 is applicable when data already exists and point 2 is applicable when there are no data.
First of all a big thank you for taking time to come up with the code.
I request your assistance with regards to below 2 points -
1) If data exists macro should prompt for a message box stating "data exists insert new sheet" and then opens the sheet specified and paste data in respective ranges.
2)Above code does not open specified sheet. I want macro to open the specified sheet and then paste the data
Note :
(if this makes any sense)
Point 1 is applicable when data already exists and point 2 is applicable when there are no data.
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Oct 21, 2015 at 08:56 PM
Oct 21, 2015 at 08:56 PM
If data exists, still paste ? I think you meant to say if data exists show a message. There is a message that shows up, if there is data in cell a1 of the target sheet. (read the comments and make adjustment as necessary)
for have sheet open, i think u meant that target sheet should be activate
in that case, activate the workbook, and select the sheet via code.
for have sheet open, i think u meant that target sheet should be activate
in that case, activate the workbook, and select the sheet via code.
bimmy80
Posts
6
Registration date
Saturday October 17, 2015
Status
Member
Last seen
November 19, 2015
Oct 22, 2015 at 02:29 AM
Oct 22, 2015 at 02:29 AM
Greetings rizvisa1,
Let me explain.
Currently what the code does is if data exists in cell a1 then it shows the message, which is fine.
After the message is shown the code should display a message box to input new sheet.
It will then again check for data in the specified sheet in cell a1.
Macro will continue to do this (I think its called a continuous loop) until it does not come across any data in the specified sheet in cell a1.
I humbly request for your patience in getting this part correct.
Below are 3 examples which will help you in understanding how the macro should work
1st example :
When the macro is run it asks for sheet name, i insert 2, macro pastes data in 2.
2nd example :
When the macro is run it asks for sheet name, i insert 2, message appears data exist, input box appears to insert new sheet, i insert 3, macro pastes data in 3.
3rd example (continuous loop) :
When the macro is run it asks for sheet name, i insert 2, message appears data exist, input box appears to insert new sheet, i insert 3, message appears data exist, input box appears to insert new sheet, i insert 4, macro pastes data in 4.
Let me explain.
Currently what the code does is if data exists in cell a1 then it shows the message, which is fine.
After the message is shown the code should display a message box to input new sheet.
It will then again check for data in the specified sheet in cell a1.
Macro will continue to do this (I think its called a continuous loop) until it does not come across any data in the specified sheet in cell a1.
I humbly request for your patience in getting this part correct.
Below are 3 examples which will help you in understanding how the macro should work
1st example :
When the macro is run it asks for sheet name, i insert 2, macro pastes data in 2.
2nd example :
When the macro is run it asks for sheet name, i insert 2, message appears data exist, input box appears to insert new sheet, i insert 3, macro pastes data in 3.
3rd example (continuous loop) :
When the macro is run it asks for sheet name, i insert 2, message appears data exist, input box appears to insert new sheet, i insert 3, message appears data exist, input box appears to insert new sheet, i insert 4, macro pastes data in 4.
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Oct 22, 2015 at 07:23 AM
Oct 22, 2015 at 07:23 AM
here is with your loop
Sub TransferDataV2()
'transfer stuff from this workbook to workbook 2
Dim strPath2 As String
Dim wbkWorkbook1 As Workbook
Dim wbkWorkbook2 As Workbook
Dim strTargetSheet As String
'define paths and filenames
strPath2 = "D:\Master.xlsx"
'open files
Set wbkWorkbook1 = ThisWorkbook
Set wbkWorkbook2 = Workbooks.Open(strPath2)
'getting the target sheet name.
Do
strTargetSheet = InputBox("Enter the target sheet name", "Target Sheet ...")
strTargetSheet = Trim(strTargetSheet) 'remove any leading and trailing spaces
If (strTargetSheet = vbNullString) Then 'check if there is no data
MsgBox "No Name entered"
End 'terminate
End If
'check if cell A1 has any data on target sheet. Hopefully you have at least one cell that would be
'always populated. With this, it is checking is A1 is not null
If (wbkWorkbook2.Worksheets(strTargetSheet).Range("A1") <> "") Then
MsgBox "Data Already exists"
strTargetSheet = vbNullString ' remove the name
End If
Loop Until (strTargetSheet <> vbNullString) 'be in a loop till sheet name is not ""
wbkWorkbook2.Worksheets(strTargetSheet).Range("A1:C8").Value = _
wbkWorkbook1.Worksheets("Sheet1").Range("A1:C8").Value
wbkWorkbook2.Worksheets(strTargetSheet).Range("E1:N1500").Value = _
wbkWorkbook1.Worksheets("Sheet1").Range("E1:N1500").Value
'close the workbook
wbkWorkbook2.Close (True)
End Sub
Didn't find the answer you are looking for?
Ask a question
bimmy80
Posts
6
Registration date
Saturday October 17, 2015
Status
Member
Last seen
November 19, 2015
Oct 23, 2015 at 10:11 PM
Oct 23, 2015 at 10:11 PM
Hi rizvisa1,
Perfect.
Appreciate you for giving your time and patience in solving my query.
Thanks a tonne.
Perfect.
Appreciate you for giving your time and patience in solving my query.
Thanks a tonne.