Range problem

ppapp44

New Member
Joined
Mar 6, 2017
Messages
1
Dear Team!

Finally I have only a very short test code to test range (for copy).
I tried R1C1 and the original style but the range object doesn't work.

"Method "range" of Object '_global' failed" (1004) or (I used "A1" as well) "object variable or with block variable not set" (91) and (somehow) "Application defined or object defined error"
RefernceStyle R1C1 is on or off (the message is different but the problem is the same
In this case the Cells(1,1) shows the content of A1.
I have multi language (Hungarian and English) Win10, Office 2013. I implemented the TBarCode Add-ins (30daysdemo) a fewdays ago.

This the code:
'Application.ReferenceStyle = xlR1C1
Worksheets("eladas").Select
Dim rng As range
rng = ThisWorkbook.Worksheets("eladas").range(Cells(1, 1))
Worksheets("eladas").rng.Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Cikktorzs").Select
ActiveSheet.Paste

For Index = 1 To 500
Debug.Print Error$(Index)
Next Index
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
When setting an object you must use the 'Set' keyword so it should read
Code:
[B][COLOR=#ff0000]Set[/COLOR][/B] [COLOR=#333333][FONT='inherit']rng = ThisWorkbook.Worksheets("eladas").range(Cells(1, 1))[/FONT][/COLOR]
 
Last edited:
Upvote 0
You could simplify the code to something like this:

Code:
Sub CodeReduction()
Dim wsEladas As Worksheet, wsCikktorz As Worksheet

Set wsEladas = ThisWorkbook.Worksheets("eladas")
Set wsCikktorz = ThisWorkbook.Worksheets("Cikktorzs")

wsEladas.Cells(1, 1).Copy wsCikktorz.Cells(1, 1)

For Index = 1 To 500
    Debug.Print Error$(Index)
Next Index

End Sub

Generally there's no need to select ranges before you apply a method (like COPY).

Hope that helps
Caleeco
 
Last edited:
Upvote 0
Not sure what you are doing with rest of the code but for rng try this.
Code:
Dim rng As range

    Set rng = ThisWorkbook.Worksheets("eladas").Cells(1, 1)

    rng.Copy
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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