VBA: copy using right command

brian_griffin

New Member
Joined
Oct 30, 2012
Messages
7
Hello,

I would like to use a VBA command to copy a specific part (date) of a certain cell in various workbooks.

I have the following code:
Code:
WBZ.Worksheets(1).Range("G" & WBZ.Worksheets(1).Range("G65536").End(xlUp).Row + 1).Value = Right(WBQ.Worksheets(1).Range("D86").Copy, 4)

Unfortunately, I get the error "-2147221080" with the error description "Automation error".

If I rephrase a part of the code to:
Code:
WBZ.Worksheets(1).Range("G" &  WBZ.Worksheets(1).Range("G65536").End(xlUp).Row + 1).Value = 2004
The command is working properly.

Does anyone have an idea that could be wrong with my command?

Thank you very much in advance.

Best
Brian
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi jonmo1

Thanks for your suggestion.

Unfortunately, it does not work.

Code:
WBZ.Worksheets(1).Range("G" & WBZ.Worksheets(1).Range("G65536").End(xlUp).Row + 1).Value = Right(WBQ.Worksheets(1).Range("D89"), 1)

I get the same error for this command.

Best
Brian
 
Upvote 0
What are WBZ and WBQ ?
Can you post the code that initializes those variables?

I presume they are workbook variables
something like

Dim WBZ As Workbook, WBQ As Workbook

Set WBZ = Workbooks("BookZName.xls")
Set WBQ = Workbooks("BookQName.xls")


The code you just posted works for me If I remove those two references (making it just refer to the current active book)


Plus, you changed more than I suggested you change..
You changed the 4 to 1 in the Right function.
 
Upvote 0
First, you are right.

I changed the code to check whether there is any problem with the cell or the number of characters.

Second, you are also right.

I messed something up with the initialization.


Now the code is working fine.

Thanks :)

Brian
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

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