can you advise on code path please

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Hi,
Could you advise the code for the following please,i will then continue from there with the others i need to do.

I will add this to a button to transfer cell vales to my end of month sheet.

Worksheet called INCOME1
Copy cell value E32 & paste to Worksheet path shown below,

C,USERS,IAN,DESKTOP,EBAY,ACCOUNTS,PREVIOUS ACCOUNTS,2018 - 2019,SUMMARY 2018 - 2019,SHEET1, then cell E49

Thanks
 
Do you have a Sheet named Sheet1? If yes, is it spelled as shown or all caps as in your first post? If Sheet1 is not part of your workbook, then change the sheet name.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
This is how it is,

Code:
Private Sub CommandButton2_Click()    Dim Answer As Long
    Dim path As String
    path = "C\Users\Ian\Desktop\EBAY\ACCOUNTS\PREVIOUS ACCOUNTS\2018 - 2019\SUMARY 2018 - 2019\"
    Answer = MsgBox("Transfer Values To Summary Sheet ?", vbYesNo + vbInformation, "End Of Month Accounts")
    If Answer = vbYes Then
        Sheets("INCOME1").Range("E32").Copy path & Sheets("Sheet1").Range("E49")
        ActiveWorkbook.Save
    End If


End Sub

The pasted value in for the destination workbook named SUMARY 2018 - 2019 Sheet1 cell E49

I cant see this error at all

I can get it to copy / paste in the same sheet but not the sheet in the other folder
 
Last edited:
Upvote 0
Trying to find where the issue is i have put the excel file on the desktop & renamed a few things just to make things more simple etc but still get the run time error 9

Code:
Private Sub CommandButton2_Click()    Dim Answer As Long
    Dim path As String
    path = "C:\Users\Ian\Desktop\A\"
    Answer = MsgBox("Transfer Values To Summary Sheet ?", vbYesNo + vbInformation, "End Of Month Accounts")
    If Answer = vbYes Then
        Sheets("Z").Range("E32").Copy path & Sheets("ABC").Range("E49")
        ActiveWorkbook.Save
    End If


End Sub

This is in yellow

Code:
Sheets("Z").Range("E32").Copy path & Sheets("ABC").Range("E49")

Can you advise at what point doe it fail.
Has it copied the value but doing the paste is the issue or did it fail just trying to copy it ?
 
Upvote 0
If it helps this does the copy / paste ok

Code:
    Range("E32").Select
    Selection.Copy
    Windows("A.xlsm").Activate
    Range("E49").Select
    ActiveSheet.Paste
    Range("G49").Select
 
Upvote 0
Ok. Just realized what is missing. What is the file name that you are pasting into. That is missing. It needs to have the the extension also.
 
Upvote 0
So going back to the original code shown below,

The name of the file it is to copy from is called ACCOUNTS.xlsm

The file to paste to is called SUMARY 2018 - 2019.xlsm

Code:
Private Sub CommandButton2_Click()  Dim Answer As Long
    Dim path As String
    path = "C\Users\Ian\Desktop\EBAY\ACCOUNTS\PREVIOUS ACCOUNTS\2018 - 2019\SUMARY 2018 - 2019\"
    Answer = MsgBox("Transfer Values To Summary Sheet ?", vbYesNo + vbInformation, "End Of Month Accounts")
    If Answer = vbYes Then
        Sheets("INCOME1").Range("E32").Copy path & Sheets("Sheet1").Range("E49")
        ActiveWorkbook.Save
    End If


End Sub
 
Upvote 0
Morning,
Is anybody available to advise the correct code for when i paste these values.

Thanks
 
Upvote 0
Ok
I read the issue is that the workbook is closed.
So we need to copy the code from the current open workbook.
Then open the workbook that is currently closed.
Then pasted to this workbook.
Then close this workbook.


If it is easier / quicker i can have both workbooks open so i then just press the button and copy from one sheet to another sheet.

I say easier / quicker as i now need to speed up with this.

Thanks
 
Upvote 0
I think that you need to change this line of code

path = "C\Users\Ian\Desktop\EBAY\ACCOUNTS\PREVIOUS ACCOUNTS\2018 - 2019\SUMARY 2018 - 2019"

to


path = "C\Users\Ian\Desktop\EBAY\ACCOUNTS\PREVIOUS ACCOUNTS\2018 - 2019\SUMARY 2018 - 2019.xlsm"
 
Last edited:
Upvote 0
Same run time error message.

So i made this as simple as it ca possibly be to try and get it to work.
Two workbooks.

One called WB1
Only one worksheet inside called C

Other workbook called WB2
Only one worksheet inside called P

WB1 has a button with this code shown below.


Code:
Private Sub CommandButton1_Click()Workbooks("WB1.xls").Sheets(C).Range("A1").Copy _
    Destination:=Workbooks("WB2").Sheets(P).Range("A1")
End Sub

Yet i still get run time error 9 message.
Subscript out of range.

I cant see how or why this is so hard.
There must be something else which isnt allowing this to work.
These two workbooks WB1 & WB2 were both open but still i get run time error 9 message.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top