Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Narrow Range based on Selection in Another Range | Excel Discussion (Misc queries) | |||
Identifying a selection of a selection of a range | Excel Worksheet Functions | |||
range selection problem | Excel Programming | |||
Excel VBA - Range(Selection, Selection.End(xlDown)).Name issue. | Excel Programming | |||
Range selection problem | Excel Programming |