Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Range selection problem

I am writing a routine to import data from one workbook to another and run
checks on it. This will be done regularly, so the old data has to be first
deleted from the destination workbook. The latest code is below. If I
comment out everything down to "Now import new data", it runs OK. When I
remove the comments, it crashes at the line indicated with "Compile error -
variable not defined". The x1Down in that line is highlighted. I don't
understand this, as the lines seem identical. What am I missing?


' First, delete old data
Application.ScreenUpdating = False
Windows("Broker return example.xls").Activate
Sheets("Checking (1)").Select
Range("A8").Select
Range(Selection, Selection.End(x1Down)).Select <<<<<==== This does not
work
Selection.EntireRow.Delete

' Now check the new data




' Now import new data

Windows("Broker return example.xls").Activate
Sheets("Sheet1").Select
Range("A7").Select
Range(Selection, Selection.End(xlDown)).Select <<<<<<==== This
works
Selection.Resize(, Selection.Columns.Count + 17).Select
Selection.Copy
Windows("Proforma bordereau.xls").Activate
Sheets("Checking (1)").Select
Range("A7").Select
ActiveSheet.Paste
Application.CutCopyMode = False



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Range selection problem

You have x - ONE - down

it should be x - L - down

xlDown versus
x1Down

--
Regards,
Tom Ogilvy

"Brian" wrote in message
...
I am writing a routine to import data from one workbook to another and run
checks on it. This will be done regularly, so the old data has to be first
deleted from the destination workbook. The latest code is below. If I
comment out everything down to "Now import new data", it runs OK. When I
remove the comments, it crashes at the line indicated with "Compile

error -
variable not defined". The x1Down in that line is highlighted. I don't
understand this, as the lines seem identical. What am I missing?


' First, delete old data
Application.ScreenUpdating = False
Windows("Broker return example.xls").Activate
Sheets("Checking (1)").Select
Range("A8").Select
Range(Selection, Selection.End(x1Down)).Select <<<<<==== This does

not
work
Selection.EntireRow.Delete

' Now check the new data




' Now import new data

Windows("Broker return example.xls").Activate
Sheets("Sheet1").Select
Range("A7").Select
Range(Selection, Selection.End(xlDown)).Select <<<<<<==== This
works
Selection.Resize(, Selection.Columns.Count + 17).Select
Selection.Copy
Windows("Proforma bordereau.xls").Activate
Sheets("Checking (1)").Select
Range("A7").Select
ActiveSheet.Paste
Application.CutCopyMode = False





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Range selection problem

If you put Option Explicit at the top of your module, you'd find that

x1Down

is highlighted when you compiled.

xLDown

is a defined constant,

x(one)Down

isn't.



In article ,
"Brian" wrote:

I am writing a routine to import data from one workbook to another and run
checks on it. This will be done regularly, so the old data has to be first
deleted from the destination workbook. The latest code is below. If I
comment out everything down to "Now import new data", it runs OK. When I
remove the comments, it crashes at the line indicated with "Compile error -
variable not defined". The x1Down in that line is highlighted. I don't
understand this, as the lines seem identical. What am I missing?


' First, delete old data
Application.ScreenUpdating = False
Windows("Broker return example.xls").Activate
Sheets("Checking (1)").Select
Range("A8").Select
Range(Selection, Selection.End(x1Down)).Select <<<<<==== This does not
work
Selection.EntireRow.Delete

' Now check the new data




' Now import new data

Windows("Broker return example.xls").Activate
Sheets("Sheet1").Select
Range("A7").Select
Range(Selection, Selection.End(xlDown)).Select <<<<<<==== This
works
Selection.Resize(, Selection.Columns.Count + 17).Select
Selection.Copy
Windows("Proforma bordereau.xls").Activate
Sheets("Checking (1)").Select
Range("A7").Select
ActiveSheet.Paste
Application.CutCopyMode = False

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Range selection problem

Thanks to you both for that simple - and essential - insight. I think my
eyes need to take a break.


"Tom Ogilvy" wrote in message
...
You have x - ONE - down

it should be x - L - down

xlDown versus
x1Down

--
Regards,
Tom Ogilvy

"Brian" wrote in message
...
I am writing a routine to import data from one workbook to another and

run
checks on it. This will be done regularly, so the old data has to be

first
deleted from the destination workbook. The latest code is below. If I
comment out everything down to "Now import new data", it runs OK. When I
remove the comments, it crashes at the line indicated with "Compile

error -
variable not defined". The x1Down in that line is highlighted. I don't
understand this, as the lines seem identical. What am I missing?


' First, delete old data
Application.ScreenUpdating = False
Windows("Broker return example.xls").Activate
Sheets("Checking (1)").Select
Range("A8").Select
Range(Selection, Selection.End(x1Down)).Select <<<<<==== This does

not
work
Selection.EntireRow.Delete

' Now check the new data




' Now import new data

Windows("Broker return example.xls").Activate
Sheets("Sheet1").Select
Range("A7").Select
Range(Selection, Selection.End(xlDown)).Select <<<<<<====

This
works
Selection.Resize(, Selection.Columns.Count + 17).Select
Selection.Copy
Windows("Proforma bordereau.xls").Activate
Sheets("Checking (1)").Select
Range("A7").Select
ActiveSheet.Paste
Application.CutCopyMode = False







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Narrow Range based on Selection in Another Range David Excel Discussion (Misc queries) 3 July 1st 07 05:12 PM
Identifying a selection of a selection of a range swimfast Excel Worksheet Functions 1 March 1st 07 02:51 AM
range selection problem derekc[_12_] Excel Programming 2 June 18th 04 04:41 PM
Excel VBA - Range(Selection, Selection.End(xlDown)).Name issue. jonH Excel Programming 3 June 7th 04 09:13 PM
Range selection problem SotjeRuud Excel Programming 1 August 27th 03 12:41 PM


All times are GMT +1. The time now is 02:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"