"ThisWorkbook" VBA help

Wamhoi

New Member
Joined
Mar 4, 2011
Messages
48
Hi,

I'm trying to copy data from a Workbook to the Master Workbook (Containing Macro). I created the following formula that keeps breaking.

With Thisworkbook.Sheets("Data").Range("A1").Select
.Range("A65536").End(xlUp).Offset(1, 0).Select
ActiveSheet.PasteSpecial Paste:=xlValues
End With

Any Ideas?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You could just use:
Code:
Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).PasteSpecial Paste:=xlValues
Or easier to read:
Code:
Dim i as Long
i = Range("A" & Rows.Count).End(xlUp).Row
Range("A1:A" & i).Pastespecial Paste:=xlValues
Your code implies you're already in the active workbook and sheet you want to paste the values into so there doesn't appear to be any point using the WITH part of your code to define as This Workbook.
 
Upvote 0
Code:
With ThisWorkbook.Sheets("Data")
   .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlValues
End With
 
Upvote 0
Ignore my reply, mis-read the question, apologies - can't seem to edit my answer either.
 
Upvote 0
Does your code workbook have a sheet called Data in it? Assuming it does, do you have any ActiveX controls on the sheet?
Also, does the ThisWorkbook module appear in the workbook project with that name? (it sounds to me as though you might have a corrupt workbook)
 
Upvote 0
Hi, I did get it to work. I just copied the Macro into a fresh workbook then ran it and it worked great!

In the old workbook I did have Data but I'm not sure about the activex

Either way, thank you soo much for your help.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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