Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Run-time error 1004

Hi,

I'm working on a program and have received the following error message when I
try to run it.

"Run-time error 104
Application-defined or object-defined error"

I am trying to use a counter to transfer cell data from sheet 1 to sheet 2.
For example, I have data in the first five rows in column A. I want to, say,
transter the data from the last four rows in Col A to sheet 2. But I will do
it according which cell is made active based on a "counter" value. Right now
I am only writing part of that part of the program. Here is my code:

Sub MySub()
'Transfer sheet data according to i
Dim Total As Double
Dim i As Integer
i = 1
Total = 1
For i = 1 To 3
Total = Total + i
Fred
Next i
End Sub

Sub Fred()

Worksheets("Sheet2").Cells(Total, 1).Value = Worksheets("Sheet1").Cells(Total,
1).Value

End Sub



For example, when the counter is 2 the value in cell (2,1) in sheet 1 is placed
in cell (2,1) on sheet 2. When the counter is 4, the value in cell (4,1) in
sheet 1 is placed in cell (4,1). Hope this is clear. Can anyone tell me what
I am doing wrong and what I can do to fix it?

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Run-time error 1004

Variables are local when declared inside a procedure, so Fred doesn't
understand what Total is (if you had Option Explicit at the top of your
module, you would have gotten a warning that Total was an undeclared
variable). You can either declare Total at the top of the module,
outside a procedure (making it global) or declare Fred() to take an
argument:

Public Sub Fred(ByVal dTotal As Double)
Worksheets("Sheet2").Cells(dTotal, 1).Value = _
Worksheets("Sheet1").Cells(dTotal, 1).Value
End Sub


then call Fred like this:

Total = Total + i
Fred Total


In article ,
OSPAM (JimFor) wrote:

Hi,

I'm working on a program and have received the following error message when I
try to run it.

"Run-time error 104
Application-defined or object-defined error"

I am trying to use a counter to transfer cell data from sheet 1 to sheet 2.
For example, I have data in the first five rows in column A. I want to, say,
transter the data from the last four rows in Col A to sheet 2. But I will do
it according which cell is made active based on a "counter" value. Right
now
I am only writing part of that part of the program. Here is my code:

Sub MySub()
'Transfer sheet data according to i
Dim Total As Double
Dim i As Integer
i = 1
Total = 1
For i = 1 To 3
Total = Total + i
Fred
Next i
End Sub

Sub Fred()

Worksheets("Sheet2").Cells(Total, 1).Value =
Worksheets("Sheet1").Cells(Total,
1).Value

End Sub



For example, when the counter is 2 the value in cell (2,1) in sheet 1 is
placed
in cell (2,1) on sheet 2. When the counter is 4, the value in cell (4,1) in
sheet 1 is placed in cell (4,1). Hope this is clear. Can anyone tell me
what
I am doing wrong and what I can do to fix it?

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default RE-Run-time error 1004

Hi
Use Option Explicit

In a module

Option Explicit
Dim Total As Double

Sub MySub()
'Transfer sheet data according to i
Dim i As Integer
Total = 1
For i = 1 To 3
Total = Total + i
Fred
Next i
End Sub

Sub Fred()
Worksheets(2).Cells(Total, 1).Value = Worksheets(1).Cells
(Total, 1).Value
End Sub

Alain CROS

-----Original Message-----
Hi,

I'm working on a program and have received the following

error message when I
try to run it.

"Run-time error 104
Application-defined or object-defined error"

I am trying to use a counter to transfer cell data from

sheet 1 to sheet 2.
For example, I have data in the first five rows in column

A. I want to, say,
transter the data from the last four rows in Col A to

sheet 2. But I will do
it according which cell is made active based on

a "counter" value. Right now
I am only writing part of that part of the program. Here

is my code:

Sub MySub()
'Transfer sheet data according to i
Dim Total As Double
Dim i As Integer
i = 1
Total = 1
For i = 1 To 3
Total = Total + i
Fred
Next i
End Sub

Sub Fred()

Worksheets("Sheet2").Cells(Total, 1).Value = Worksheets

("Sheet1").Cells(Total,
1).Value

End Sub



For example, when the counter is 2 the value in cell

(2,1) in sheet 1 is placed
in cell (2,1) on sheet 2. When the counter is 4, the

value in cell (4,1) in
sheet 1 is placed in cell (4,1). Hope this is clear.

Can anyone tell me what
I am doing wrong and what I can do to fix it?

Thanks


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default RE-Run-time error 1004

Thanks to you both.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default RE-Run-time error 1004

Still had the same error message after putting in an Option Explicit line Did
some more research. If anyone is interested, here is what seemed to be what
was wrong. In addition to not including "Option Explicit," I was passing an
argument to Fred but did not tell Fred what it was. There was nothing in the
parenthesis. This is the new program which seems to work. Note that I tell
Fred to expect the value in "Total" by putting "Total" inside the parentheses
after the word "Fred." Thanks for helping me think in the right direction.


Option Explicit
Sub MySub()
'Transfer sheet data according to i
Dim Total As Double
Dim i As Integer
Total = 0
For i = 1 To 3
Total = Total + i
Fred (Total)
Next i
End Sub

Sub Fred(Total)
Worksheets("Sheet2").Cells(Total, 1).Value = Worksheets("Sheet1").Cells(Total,
1).Value
End Sub


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
run time error 1004 Louise Excel Worksheet Functions 0 January 18th 07 08:16 PM
Run-Time error '1004' [email protected] Excel Discussion (Misc queries) 3 March 29th 06 08:13 PM
Run time error 1004, General ODBC error [email protected] New Users to Excel 0 September 19th 05 01:41 AM
Run-Time Error 1004 George Nicholson[_2_] Excel Programming 0 July 27th 04 09:49 PM
Run Time Error 1004 Lars Kofod Excel Programming 1 December 5th 03 02:56 AM


All times are GMT +1. The time now is 05:37 PM.

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

About Us

"It's about Microsoft Excel"