ThisWorkbook paste

waldymar

Board Regular
Joined
Feb 19, 2009
Messages
238
Dear all,

I'm trying to copy a data from the open file into the code-running file:

Code:
myFile = varPath & varFileName
                                
    Set wb = Workbooks.Open(myFile)
    Set tbl = wb.Worksheets(varSheetName).Range(varRangeName)
    
    tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1, tbl.Columns.Count).Copy
    
    ThisWorkbook.Worksheets(calc).Cells(y + 1, 1).PasteSpecial

There is a problem with the last row. "calc" is the property name of the sheet in the ThisWorkbook. How can I fix it?

Thanks in advance
 
I think I realize that we spoke about different names. Codename you were talking about is probably something like:

Dim calc as a worksheet
set calc=ThisWorkbook.Worksheets("My Sheet")

No, I think we are trying to say the same thing, but missing it a bit. In the above, the worksheet's name that shows on the worksheet's tab is being referred to. Hence the quotes, as this property is referring to a string.
I meant a different sheet name:

when you are in VBA window it has 3 sections:
  1. the main one where you write code
  2. project VBAProject
  3. properties
if you go to properties attributed to your worksheet then you can give a vba name to it. it prevent code working from the sheet name change in excel.

what do you think?

Ahh, now I think we're on the same track. In the Properties window (number 3), there are two Name properties. The top one (that has the parentheses around the word Name), is the sheet's CodeName. My apologies if I was unclear.

Mark
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Ahh, now I think we're on the same track. In the Properties window (number 3), there are two Name properties. The top one (that has the parentheses around the word Name), is the sheet's CodeName. My apologies if I was unclear.

Mark

You are absolutely right! Thanks a lot, Mark. It works, but I wanted to make sure that I got it correctly. The code are gonna use other people so I wish it works smoothly.
Thanks again for your assistance, you helped a lot!
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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