Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm getting the error at the line with the asterisks. It works when I
replece the variable 'numberofRows' to a number. What am I missing, please? Private Sub CommandButton2_Click() 'Load Data Dim numberofRows As Integer, numberofColumns, nextCol As Integer Application.ScreenUpdating = False Workbooks("Replacement Strategy5.xls").Activate Sheets("Raw").Activate ActiveSheet.Columns("A:BM").Select Selection.Clear Selection.Delete Shift:=xlToLeft Workbooks.Open Filename:= _ "D:\My Documents\ENRV5608\Reports\EMMS Reports\EMMSReplacement3(EqptData).xls" Workbooks("EMMSReplacement3(EqptData).xls").Activa te Sheets("Sheet1").Activate ActiveSheet.Range("A1").Select numberofRows = ActiveCell.CurrentRegion.Rows.Count numberofColumns = ActiveCell.CurrentRegion.Columns.Count ** ActiveSheet.Range(Cells(1, 1), Cells(numberofRows, numberofColumns)).Select** nextCol = numberofColumns + 2 Selection.Copy Windows("Replacement Strategy5.xls").Activate Sheets("YTD BD").Activate Range("A1").Select ActiveSheet.Paste Thanks for any help... Jim Berglund |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Jim,
What is the value of numberofRows when the error occurs? If you click Debug and hover over the variable, you should see the value. If the number exceeds what an Integer can hold (32,767), that would cause an error. When working with rows in Excel, I typically use a Long to avoid these types of problems. If the value is something else, please post back with more info. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Jim Berglund wrote: I'm getting the error at the line with the asterisks. It works when I replece the variable 'numberofRows' to a number. What am I missing, please? Private Sub CommandButton2_Click() 'Load Data Dim numberofRows As Integer, numberofColumns, nextCol As Integer Application.ScreenUpdating = False Workbooks("Replacement Strategy5.xls").Activate Sheets("Raw").Activate ActiveSheet.Columns("A:BM").Select Selection.Clear Selection.Delete Shift:=xlToLeft Workbooks.Open Filename:= _ "D:\My Documents\ENRV5608\Reports\EMMS Reports\EMMSReplacement3(EqptData).xls" Workbooks("EMMSReplacement3(EqptData).xls").Activa te Sheets("Sheet1").Activate ActiveSheet.Range("A1").Select numberofRows = ActiveCell.CurrentRegion.Rows.Count numberofColumns = ActiveCell.CurrentRegion.Columns.Count ** ActiveSheet.Range(Cells(1, 1), Cells(numberofRows, numberofColumns)).Select** nextCol = numberofColumns + 2 Selection.Copy Windows("Replacement Strategy5.xls").Activate Sheets("YTD BD").Activate Range("A1").Select ActiveSheet.Paste Thanks for any help... Jim Berglund |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
** ActiveSheet.Range(Cells(1, 1),
Cells(numberofRows,numberofColumns)).Select** My suggestion would be to use the With command on the line as I have found that Excel occassional goes mental when using the cells command. Especially when calling a worksheet from another worksheet So With ActiveSheet Set rng = Range(Cells(1, 1), Cells(numberofRows,numberofColumns)).Select End with |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
David Adamson wrote:
My suggestion would be to use the With command on the line as I have found that Excel occassional goes mental when using the cells command. Especially when calling a worksheet from another worksheet So With ActiveSheet Set rng = Range(Cells(1, 1), Cells(numberofRows,numberofColumns)).Select End with Oh yeah - I didn't see that. But don't forget the dots: With ActiveSheet .Range(.Cells(1, 1), .Cells(numberofRows,numberofColumns)).Select End With -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for picking that up
Oh yeah - I didn't see that. But don't forget the dots: With ActiveSheet .Range(.Cells(1, 1), .Cells(numberofRows,numberofColumns)).Select End With -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks! This did the trick. Where did you get this arcane wizardry?
Jim "Jake Marx" wrote in message ... David Adamson wrote: My suggestion would be to use the With command on the line as I have found that Excel occassional goes mental when using the cells command. Especially when calling a worksheet from another worksheet So With ActiveSheet Set rng = Range(Cells(1, 1), Cells(numberofRows,numberofColumns)).Select End with Oh yeah - I didn't see that. But don't forget the dots: With ActiveSheet .Range(.Cells(1, 1), .Cells(numberofRows,numberofColumns)).Select End With -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Jim,
Jim Berglund wrote: Thanks! This did the trick. Where did you get this arcane wizardry? I don't know about wizardry, but...as David mentioned, this was an issue with not fully-qualifying your range references. When you simply use Range or Cells without specifying the Worksheet you intend, Excel assumes different things depending on your situation. For example, if you use Range("A1") from a Worksheet class module, it will always refer to that Worksheet's cell A1. However, if you use Range("A1") in a standard module (or a class module other than a Worksheet), Excel will assume you want to work with cell A1 from the active Worksheet. Since your code was on a Worksheet class module but you're intending to work with ranges on another Worksheet, you have to be explicit. Using a With statement is the easiest way to do this, as you don't have to type Worksheets("Raw") each time. Hopefully, that makes some sense. If not, let me know and I'll try to expand on it a bit. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
runtime error 1004 | Excel Discussion (Misc queries) | |||
Runtime Error '1004' | Excel Discussion (Misc queries) | |||
runtime error 1004 | Excel Programming | |||
Runtime Error 1004 | Excel Programming | |||
runtime error 1004 | Excel Programming |