#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8
Default vba outcome

can anyone tell me if theres any errors in this and what the outcome
would be?

sub test ()

dim I, J As Integer
dim x as single
for i = 1 to length
for j = 1 to (length - i)
If A(j) < A )j +1) Then
x = a(j +1) = A(j)
A(j) = x
end if
next j
next i
end sub

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default vba outcome

Test it!

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"harry buggy" wrote in message
oups.com...
can anyone tell me if theres any errors in this and what the outcome
would be?

sub test ()

dim I, J As Integer
dim x as single
for i = 1 to length
for j = 1 to (length - i)
If A(j) < A )j +1) Then
x = a(j +1) = A(j)
A(j) = x
end if
next j
next i
end sub



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
bj bj is offline
external usenet poster
 
Posts: 1,397
Default vba outcome

several things

where is length defined?

I would do it as
for i = 2 to length
(by going from 1 to length you have the j going from one to zero the first
iteration, whch it wont do

If A(j) < A )j +1) Then
needs to be
If A(j) < A (j +1) Then

x = a(j +1) = A(j)
needs to be
x=A(j+1)
A(J+1)=A(J)


"harry buggy" wrote:

can anyone tell me if theres any errors in this and what the outcome
would be?

sub test ()

dim I, J As Integer
dim x as single
for i = 1 to length
for j = 1 to (length - i)
If A(j) < A )j +1) Then
x = a(j +1) = A(j)
A(j) = x
end if
next j
next i
end sub


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,856
Default vba outcome

1. You haven't defined what length is, nor the array A.
2. You mix upper and lower case i and j.
3. On your 7th line you have a closed bracket before the j+1 term -
should be open bracket.
4. Your 8th line does not make sense.

As for the outcome, are you trying to do a crude bubble sort?

Hope this helps.

Pete

On Aug 29, 12:19 pm, harry buggy wrote:
can anyone tell me if theres any errors in this and what the outcome
would be?

sub test ()

dim I, J As Integer
dim x as single
for i = 1 to length
for j = 1 to (length - i)
If A(j) < A )j +1) Then
x = a(j +1) = A(j)
A(j) = x
end if
next j
next i
end sub



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,651
Default vba outcome

Yes there are errors.

You can try proof-reading your macro, and/or you can try to run it and see
what errors it tells you about.
--
David Biddulph

"harry buggy" wrote in message
oups.com...
can anyone tell me if theres any errors in this and what the outcome
would be?

sub test ()

dim I, J As Integer
dim x as single
for i = 1 to length
for j = 1 to (length - i)
If A(j) < A )j +1) Then
x = a(j +1) = A(j)
A(j) = x
end if
next j
next i
end sub





  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,202
Default vba outcome

can anyone tell me if theres any errors in this...

sub test ()

dim I, J As Integer


The above statement only declares the variable J as an Integer; the variable
I will be declared as a Variant. In VBA, you must declare each variable's
type individually. So, you could write the above this way...

Dim I As Integer, J As Integer

or this way (your choice)....

Dim I As Integer
Dim J As Integer

My personal preference is for the latter, but that is only a personal
preference.

Rick

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
vba outcome harry buggy Excel Worksheet Functions 2 August 29th 07 03:18 PM
How do I caclculate a ratio where the outcome is X to 1 djerome Excel Worksheet Functions 4 August 30th 06 09:53 PM
format the outcome of a formula tinester Excel Discussion (Misc queries) 3 April 12th 06 07:58 PM
How to calculate a sum as one outcome of an IF statement barb in NC Excel Worksheet Functions 2 March 31st 05 08:01 PM
Stop % showing in outcome of formula Beginner Excel Worksheet Functions 2 January 10th 05 08:09 PM


All times are GMT +1. The time now is 12:28 AM.

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"