Simple VBA code not working on new laptop

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following code that is working fine on my PC, but I just got a new
laptop and it stops working on the line "ActiveSheet.Paste". I don't know
where to begin to look. Security is set to low. Thanks for your help.

Sub OpOutOfSequence()

Range("A1").Select
Range(Selection, Selection.End(x1ToRight)).Select
Range(Selection, Selection.End(x1down)).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
 
Put Option Explicit at the top of that module, try to compile (Debug,
Compile VBA Project) and you will see what the trouble is.
Best to have this always at the top of all modules, so do:
Tools, Options, Editor, tick Require variable declaration.

RBS
 
You have in two places X1 instead of Xl (one instead of the letter l).

Sub OpOutOfSequence()

Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
End Sub
 
On top of the other responses:

This line of code

Range("A1").currentregion.copy

can replace ALL of these lines

Range("A1").Select
Range(Selection, Selection.End(x1ToRight)).Select
Range(Selection, Selection.End(x1down)).Select
Selection.Copy
 
It was my typo below. I typed x1. The code is actually xl so that has
nothing to do with why the code isn't working. It must have something to do
with a laptop setting??? Any other ideas? Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top