Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Application-defined or object-defined error

Error:

Run-time error '1004':
Application-defined or object-defined error

Compares cells in column Z with the Random number generated to see if it has
already been generated. I think it has something to do with "m".

RandomNumber = Int(1000 * Rnd + 1)
m = .Cells(1, 27)
For k = 1 To m
If RandomNumber = .Cells(k, 26) Then
RandomNumber = Int(1000 * Rnd + 1)
End If
Next k
.Cells(m, 26) = RandomNumber
m = m + 1
.Cells(1, 27) = m
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Application-defined or object-defined error

Sub servient()
With Sheets("Sheet1")
RandomNumber = Int(1000 * Rnd + 1)
m = .Cells(1, 27).Value
For k = 1 To m
If RandomNumber = .Cells(k, 26).Value Then
RandomNumber = Int(1000 * Rnd + 1)
End If
Next k
.Cells(m, 26).Value = RandomNumber
m = m + 1
.Cells(1, 27).Value = m
End With
End Sub

--
Gary''s Student - gsnu200906
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Application-defined or object-defined error

Can you post a larger chunk of your code?

..Cells: Anytime you see a keyword prefaced by a ".", I'd expect to see a
'With X' statement above it somewhere, and an 'end with' below somewhere. If
you are missing this prefix, that would cause problems.

Sheet1.cells(1,27) refers to cell "AA1" in Column/Row notation. So, assuming
you have a valid value in AA1; you are checking each value in Col Z for that
many rows, and if you find a match, you generate a new random number.

I'm not sure if this will really have the result you intend; you reset the
random number and continue checking the rest of column Z, so it is possible
that the new random number will match one of the rows you have already
processed- your code doesn't go back and check previous values for matches
when you create a new random number.

There are a couple of ways to address this, but the most simple option would
be to set k=0 when you create the new random number, so your loop will start
searching from the top again.

Alternatively, you could use application.match against all of column Z and
determine if there are any matches, rather than cycling through each value
one at a time.

(aircode)

FoundMatchingValue = 1
Do Until IsError(FoundMatchingValue)
RandomNumber = Int(1000 * Rnd + 1)
FoundMatchingValue = Application.Match(RandomNumber,
Sheet1.Range("Z1:Z100"), False)
Loop

HTH,
Keith

"Philosophaie" wrote:

Error:

Run-time error '1004':
Application-defined or object-defined error

Compares cells in column Z with the Random number generated to see if it has
already been generated. I think it has something to do with "m".

RandomNumber = Int(1000 * Rnd + 1)
m = .Cells(1, 27)
For k = 1 To m
If RandomNumber = .Cells(k, 26) Then
RandomNumber = Int(1000 * Rnd + 1)
End If
Next k
.Cells(m, 26) = RandomNumber
m = m + 1
.Cells(1, 27) = m

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 '50290': Application-defined or object-defined erro Macro button Excel Discussion (Misc queries) 1 March 12th 09 10:59 AM
Export a chart in a GIF file. Run-time error '1004': Application-defined or object-defined error; [email protected] Excel Programming 4 September 16th 07 11:09 PM
Application-Defined or object defined error 1004 When ran on exel97 but not 2003 bornweb Excel Programming 0 February 17th 07 11:30 PM
Copying A Range of Cells From one Sheet to Another - Error Application Defined or Object Defined Matt[_39_] Excel Programming 3 July 25th 06 01:13 AM
Runtime error 1004- application defined or object defined erro Jim Thomlinson[_5_] Excel Programming 0 February 6th 06 09:29 PM


All times are GMT +1. The time now is 04:53 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"