Question

Comparing sets of data with a number (lower and upper limit) --part2

Asked by: ceneiqe

this is a continuation of my prior question:
http://www.experts-exchange.com/Q_23716078.html

1. if i want to choose a bigger number, what should i do ?
ie. if 0.75  and 1.25 , they are both 0.25 away from 1.
but i would like to choose the bigger number instead. ie. 1.25.

2. and once 1.25 is chosen , the result will show 1.25 and then inserted a column beside "Result"
and it shows the column header of where 1.25 is from.
for eg. the column title of 1.25 is BOX1. so it should show:

1.25   BOX1

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-06-21 at 11:22:18ID24509589
Topics

Microsoft Excel Spreadsheet Software

,

Visual Basic Programming

Participating Experts
2
Points
150
Comments
42

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Get Upper and lower bound of an array at runtime.
    A silly question,please help me. can I get the Upper & lower bound of an array at runtime? example: TCHAR SomeArray[]= { "aaa", "bbb", ... }; ... if ( (dwIndex &...
  2. Upper limits and Lower limits
    Is there a way to set an Upper and Lower limit to show a line on a chart. I want to show where a value should be vs the the bar chart. Based on source data for Upper Limit and Lower Limit. | _|_|___________ Upper limit | | _|_|___________ Lower Limit | | Something lik...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: patrickabPosted on 2009-06-23 at 03:11:20ID: 24690436

ceneiqe,

You could use this:

=INDEX(A1:A3,MATCH(C2,A1:A3,0)+1,1)

It's in the attached file.

Patrick

 

by: ceneiqePosted on 2009-07-04 at 08:48:26ID: 24777178

but i can't see the VBA code in the attached file.
?

 

by: patrickabPosted on 2009-07-04 at 11:08:32ID: 24777543

ceneiqe,

>but i can't see the VBA code in the attached file.

Nor can I! And the reason is because there isn't any VBA. You didn't ask for VBA so I provided a formula as a solution.

Patrick

 

by: ceneiqePosted on 2009-07-05 at 07:46:06ID: 24780142

ok , sorry i forgot.
I have attached the file.
see my comments inside.
previous VBA code in sheet1.

Thanks.

 

by: patrickabPosted on 2009-07-06 at 13:39:56ID: 24789025

ceneiqe,

The code below is in the attached file. Press the button to run the macro.

Hope it helps. Let me know if it doesn't do what's wanted.

Patrick

Option Explicit
Option Base 1
 
Sub aspecialmacro()
Dim rng As Range
Dim celle As Range
Dim rowe As Long
Dim coll As New Collection
Dim k As Long, i As Long, n As Long, m As Long
Dim temp As Double
Dim myarray(7) As Double
Dim str As String
 
Application.ScreenUpdating = False
 
With Sheets("Sheet1")
    For i = 3 To .Cells(.Cells.Rows.Count, "Y").End(xlUp).Row
        On Error Resume Next
        k = 1
        Set rng = Range(.Cells(i, "Y"), .Cells(i, "AE"))
        For Each celle In rng
            myarray(k) = celle
            k = k + 1
        Next celle
        
        temp = 0
        For m = 1 To 7
            For n = 1 To 7
            If myarray(m) < myarray(n) Then
                temp = myarray(m)
                myarray(m) = myarray(n)
                myarray(n) = temp
                If n = 7 Then
                    myarray(7) = temp
                End If
                temp = 0
            End If
            Next n
        Next m
            
        k = 1
        temp = 0
        Do While myarray(k) < .[AF2]
            temp = myarray(k)
            k = k + 1
            If k > 7 Then Exit Do
        Loop
        
        For m = 1 To 7
            myarray(m) = 0
        Next m
        
        .Cells(i, "AH") = temp
        For m = 25 To 31
            If .Cells(i, m) = temp Then
                .Cells(i, "AI") = .Cells(1, m)
            End If
        Next m
    Next i
    
End With
 
Application.ScreenUpdating = True
 
End Sub

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:

Select allOpen in new window

 

by: patrickabPosted on 2009-07-06 at 16:25:07ID: 24790154

The attached file has a comment for cell AF2 which helps to explain how the macro works - well in part.

 

by: ceneiqePosted on 2009-07-08 at 08:03:53ID: 24804535

ok, but the results should be in Column AF and AG
and not in Column AH and AI.

 

by: patrickabPosted on 2009-07-08 at 08:12:19ID: 24804633

>but the results should be in Column AF and AG and not in Column AH and AI.


Change these lines of code as required:

        .Cells(i, "AH") = temp
        For m = 25 To 31
            If .Cells(i, m) = temp Then
                .Cells(i, "AI") = .Cells(1, m)
            End If
        Next m

 

by: ceneiqePosted on 2009-07-12 at 08:26:47ID: 24834667

oh yes, silly me.

but what happens if the file is overight ie. for example the main file is called "MASTER FILE " with all the formulae and codes and then a new file says "Main File 1" is created (new values updated) - how can the same macro be run for the newly created file "Main File 1" ?

 

by: patrickabPosted on 2009-07-12 at 08:40:58ID: 24834730

ceneiqe,

If the file is Saved As with a new name then the macro in the original file will also be in the new file. The file name is not used in the macro so you can call the file anything you like!

If you create a totally new file and want the macro in it then this is what you need to do to install the macro in a module:

1) Press ALT+F11
2) Find the workbook name in the VBAProject window (CTRL+R if it's not visible), right-click on the file name
3) Select Insert/Module
4) Double click on the new Module
5) Paste the code into the Module under Option Explicit
6) ALT + F11 to return to the worksheet
7) Save the file
8) ALT + F8 to select and run the macro

Hope that helps

Patrick

 

by: aikimarkPosted on 2009-07-12 at 12:12:59ID: 24835423

* You could use the InputBox() function to ask you for the name of the spreadsheet.
* You could use the Application.FindFile method
* You could use the Windows API to show the file Open dialog

 

by: ceneiqePosted on 2009-07-13 at 22:02:56ID: 24846399

aikimark: could you show me step by step examples ?

Patrick : it doesn't work.i amended the codes accordingly as i have extra columns now due to add. info.
but the macro doesn't run.

 

by: patrickabPosted on 2009-07-14 at 01:41:27ID: 24847292

ceneiqe,

>but the macro doesn't run.

I'm not surprised! The columns Y to AH do not have data in all of them. The macro cannot work without data, so please add the data, and not just the word 'data'.

Patrick

 

by: patrickabPosted on 2009-07-14 at 02:01:06ID: 24847388

...and then upload the file please as I believe the code needs to be changed to cope with the extra columns.

Patrick

 

by: aikimarkPosted on 2009-07-14 at 04:41:27ID: 24848255

Dim strWorkbookName As String
Dim wbkCurrent As Workbook
 
strWorkbookName = InputBox("Enter the workbook path\name") 
If Len(strWorkbookName) = 0 Then
  Exit Sub
End If
 
strWorkbookName = InputBox("Enter workbook path\name")
Workbooks.Open strWorkbookName 
Set wbkCurrent = ActiveWorkbook
With wbkCurrent 
  With .Sheets("Sheet1")
 
   'add your processing code here
 
  End With
End With
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:

Select allOpen in new window

 

by: ceneiqePosted on 2009-07-14 at 07:30:11ID: 24849911

ok patrick , file attached as instructed.

see my comments inside.

 

by: ceneiqePosted on 2009-07-14 at 07:37:22ID: 24850002

aikimark:

This is the code and i place them in module1.

But i encounter the following error :
Macros are disabled because the security level is set to high and a digitally signed trusted certificate is not attached to the macros. to run the macros, change the security level to a lower setting (not recommended), or request the macros be signed by the author  using a certificate issued by a certificate authority.

what has gone wrong ?

Option Explicit
Option Base 1
 
Sub aspecialmacro()
 
Dim strWorkbookName As String
Dim wbkCurrent As Workbook
 
strWorkbookName = InputBox("Enter the workbook path\name")
If Len(strWorkbookName) = 0 Then
  Exit Sub
End If
 
strWorkbookName = InputBox("Enter workbook path\name")
Workbooks.Open strWorkbookName
Set wbkCurrent = ActiveWorkbook
With wbkCurrent
  With .Sheets("Sheet1")
 
Application.ScreenUpdating = False
 
With Sheets("Sheet1")
    For i = 3 To .Cells(.Cells.Rows.Count, "Y").End(xlUp).Row
        On Error Resume Next
        k = 1
        Set rng = Range(.Cells(i, "AA"), .Cells(i, "AH"))
        For Each celle In rng
            myarray(k) = celle
            k = k + 1
        Next celle
        
        temp = 0
        For m = 1 To 7
            For n = 1 To 7
            If myarray(m) < myarray(n) Then
                temp = myarray(m)
                myarray(m) = myarray(n)
                myarray(n) = temp
                If n = 7 Then
                    myarray(7) = temp
                End If
                temp = 0
            End If
            Next n
        Next m
            
        k = 1
        temp = 0
        Do While myarray(k) < .[AI2]
            temp = myarray(k)
            k = k + 1
            If k > 7 Then Exit Do
        Loop
        
        For m = 1 To 7
            myarray(m) = 0
        Next m
        
        .Cells(i, "AH") = temp
        For m = 25 To 31
            If .Cells(i, m) = temp Then
                .Cells(i, "AI") = .Cells(1, m)
            End If
        Next m
    Next i
    
End With
 
Application.ScreenUpdating = True
 
End Sub
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:

Select allOpen in new window

 

by: patrickabPosted on 2009-07-14 at 08:28:26ID: 24850634

Try the macro in the attached file...

Patrick

 

by: patrickabPosted on 2009-07-14 at 08:31:16ID: 24850677

ceneiqe,

By the way you were asking aikimark about the code that I wrote!

You will need to set the Security leve to Medium to run my macro. It is possible that the first time you reset the Security level you will need to set it to Low, but as soon as you have run a macro you can then change it to Medium.

Patrick

 

by: ceneiqePosted on 2009-07-14 at 09:10:20ID: 24851209

patrickab:
ops sorry. don't worry, i will allocate points accordingly.

my security level is medium, so i don't undertstand what went wrong.
is there any wrong with the code after the additions of columns ?

 

by: aikimarkPosted on 2009-07-14 at 13:44:40ID: 24853880

you have two

   With .Sheets("Sheet1")

statements.  Delete one of them.

 

by: patrickabPosted on 2009-07-14 at 15:25:27ID: 24854640

Not in my original code in compare-test.xls - but yes you're right in the code that has been requoted...

 

by: patrickabPosted on 2009-07-14 at 15:33:34ID: 24854683

ps. Please try the macro in my latest file compare-test-02.xls

 

by: ceneiqePosted on 2009-07-15 at 08:07:01ID: 24860169

aikimark:
you have two

   With .Sheets("Sheet1")

statements.  Delete one of them.

>> But it doesn't help. there is an error compiling.


 

by: patrickabPosted on 2009-07-15 at 08:10:41ID: 24860216

ceneiqe,

Is there a reason that you have not yet tried my latest file?

Patrick

 

by: ceneiqePosted on 2009-07-15 at 08:19:33ID: 24860321

patrick , no it doesn't work.

sorry, i think i didn't explain my problem clear enough.

see attached.
worksheet "sheet1" = before how it looks.
worksheet "after" = after how it should be after the macro is run.

results should appear in column AI and AJ .and that a column is inserted to become column AJ.

 

by: patrickabPosted on 2009-07-15 at 08:30:47ID: 24860479

ceneiqe,

I have now completely lost the plot on this question. I now no longer understand what you are wanting. As I understand it, you specify a number and then want to extract from a small range of numbers the value that is the next smallest from the specified number.

So taking your original question example:

0.5, 1.5, 2.1, 0.43, 0.35

your condition number : 1

So from that you want the next number from the range that is smaller than 1. The answer from that range of numbers would be 0.5

If your 'condition number' had been 0.43 then the answer would have been 0.35

And yet it appears you have now changed your requirements. Do please re-state what it is that you are wanting. It is not good enough to say 'I doesn't work' when it does work but now apparently doesn't give you the answers you are wanting. So please explain your requirement again...

Patrick

 

by: ceneiqePosted on 2009-07-15 at 08:46:05ID: 24860669

the condition is already taken care of.  (see sheet 1 script)
ie. example given :
0.5, 1.5, 2.1, 0.43, 0.35
the result should be 1.5. (0.5 is also 0.5 near to 1 as to 1.5 is 0.5 to 1 - but we choose the larger number, thus 1.5)

example 2:
2.5, 0.2, 1.3, 0.6, 0.9
result = 0.9

yes, the condition number = 1
the result chosen must be nearest to 1.

now what i need is just the macro - to have the results in column AI and AJ.
 (see Module1 script)

thanks.

 

by: aikimarkPosted on 2009-07-15 at 13:22:01ID: 24863698

Add another End With statement (at the bottom) to match the new one we added at the top.

 

by: patrickabPosted on 2009-07-15 at 13:56:27ID: 24864086

ceneiqe,

Thank you for the explanation. That helped a lot.

The code below is in the attached file. Press the button to get the results.

Hope it helps

Patrick

Option Explicit
Option Base 1
 
Sub aspecialmacro()
Dim rng As Range
Dim celle As Range
Dim rowe As Long
Dim coll As New Collection
Dim k As Long, i As Long, n As Long, m As Long
Dim temp As Double
Dim myarray(8) As Double
Dim str As String
 
Application.ScreenUpdating = False
 
With Sheets("Sheet1")
    For i = 2 To .Cells(.Cells.Rows.Count, "AA").End(xlUp).Row
        On Error Resume Next
        k = 1
        Set rng = Range(.Cells(i, "AA"), .Cells(i, "AH"))
        For Each celle In rng
            myarray(k) = celle
            k = k + 1
        Next celle
        
        temp = 0
        For m = 1 To 8
            For n = 1 To 8
            If myarray(m) < myarray(n) Then
                temp = myarray(m)
                myarray(m) = myarray(n)
                myarray(n) = temp
                If n = 8 Then
                    myarray(8) = temp
                End If
                temp = 0
            End If
            Next n
        Next m
            
        k = 1
        temp = 0
        Do While myarray(k) < 1 '.Cells(i, "AI")
            temp = myarray(k)
            k = k + 1
            If k > 8 Then Exit Do
        Loop
        .Cells(i, "AI") = temp
                
        For m = 27 To 34
            If .Cells(i, m) = temp Then
                .Cells(i, "AJ") = .Cells(1, m)
            End If
        Next m
        
        For m = 1 To 8
            myarray(m) = 0
        Next m
    Next i
    
End With
 
End Sub

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:

Select allOpen in new window

 

by: patrickabPosted on 2009-07-15 at 14:10:25ID: 24864234

If you would like the values just under 1 to be made bold then you could use the attached file...

 

by: ceneiqePosted on 2009-07-23 at 09:48:19ID: 24927293

compare-test-05  is ok (good initiative for bold)  except that :
column AJ is not supposed to be already inserted.

It should be inserted after the macro is run.

the headers from Column AA to AH is the same as Column M to T.
so Column AK will show the corresponding information (chosen from M to T depending on the result in Column AI ) when the column AJ points to the headerXX.

Thus column AJ to AN should be inserted after the macro is run.
(see attached for details)

------------------------
to insert:
Column AL to AN
after running the macro

condition number is 2 instead of 1.
and then the corresponding results follow.
--------

Note: I have increased the points to 150 as i know i have required additional parts (Result2) which is not stated in the beginning to be fair.

 

by: patrickabPosted on 2009-07-23 at 12:11:19ID: 24928943

>column AJ is not supposed to be already inserted.
>It should be inserted after the macro is run.

I needs to be inserted by the macro before the results are placed in that column. I have changed the macro to do that - it's in the attached file.

I'm afraid that's as far as I can go. I don't understand your other requirements and I am about to travel for a week so it might be best to close this question.



 

by: ceneiqePosted on 2009-07-26 at 01:54:36ID: 24944798

initially the result is based on condition number = 1   (see code below)

ie. if 0.75  and 1.25 , they are both 0.25 away from 1.
but i would like to choose the bigger number instead. ie. 1.25.

But if  the condition number =2
ie. the numbers must be nearest to 2.
example in row 2:
6.27      1.50      0.50      0.90      0.20      1.10      0.00      0.00
instead of choosing 0.90, the result is now 1.5.

So i am having 2 sets of results, ie. one for Condition number =1 and then Condition number =2.

Yes, i understand, no worries, i will close both result1 and 2 is settled.
I don't like to drag either.
Anyway i have already increased the points and so i can't revert back.

   Sub FindClosest()
    Const CONDITION_NUMBER = 1
    Const COLUMNS_OF_DATA = 7
    
    Dim intCount As Integer
    Dim sngNums() As Single
    ReDim sngNums(COLUMNS_OF_DATA)
    Dim sngMinDiff As Single
    Dim sngTemp As Single
    Dim intResult As Integer
    Dim strTemp As String
    Dim lngRow As Long
    Dim strRow As String
    Dim lngBottom As Long
    
    If COLUMNS_OF_DATA > 35 Then
        MsgBox "You cannot have more than 35 columns of data to compare."
        Exit Sub
    End If
    
    ActiveCell.SpecialCells(xlLastCell).Select
    lngBottom = ActiveCell.Row
        
    For lngRow = 2 To lngBottom
        strRow = Trim(str(lngRow))
       ' Populate an array with the differences. PURPOSE: TO REDUCE NUMBER OF LOCATIONS
       For intCount = 1 To COLUMNS_OF_DATA
           If intCount < 3 Then
               strTemp = Chr(88 + intCount)
           Else
               strTemp = "A" & Chr(62 + intCount)
           End If
           sngNums(intCount) = CONDITION_NUMBER - Range(strTemp & strRow).Value
       Next
    
       ' Start by finding a value that we know is not right that we can use to work our way in.
       ' Get the larger of the differences from the smallest and largest numbers in the source range
       If COLUMNS_OF_DATA < 3 Then
           strTemp = Chr(88 + COLUMNS_OF_DATA)
       Else
           strTemp = "A" & Chr(62 + COLUMNS_OF_DATA)
       End If
       sngTemp = Abs(CONDITION_NUMBER - (Application.WorksheetFunction.Max(Range("Y" & strRow & ":" & strTemp & strRow))))
       sngMinDiff = Abs(CONDITION_NUMBER - (Application.WorksheetFunction.Min(Range("Y" & strRow & ":" & strTemp & strRow))))
       
       If sngTemp > sngMinDiff Then sngMinDiff = sngTemp
       
       ' Now as we go through the numbers, we know we'll get something that's BIGGER.
       ' Or, if they're all the same, it won't matter which we select.
       intResult = 1
       For intCount = 1 To COLUMNS_OF_DATA
           ' If the abs of the difference is smaller, collect the BIGGER number.
           If Abs(sngNums(intCount)) < sngMinDiff Then
               sngMinDiff = Abs(sngNums(intCount))
               intResult = intCount
           End If
           ' If the abs of the diff is the same, but the original # is lower than the
           ' condition, point to that one instead. RULE OF THUMB: choose nearer to 1 but eg. if btw 0.5 and 1.5, choose 1.5.
           If Abs(sngNums(intCount)) = sngMinDiff And sngNums(intCount) < 0 Then
               intResult = intCount
           End If
       Next
       If intResult < 3 Then
           strTemp = Chr(88 + intResult)
       Else
           strTemp = "A" & Chr(62 + intResult)
       End If
       ' Now intResult holds the index of the closest number that is lower than the condition.
       Range("A" & Chr(63 + COLUMNS_OF_DATA) & strRow).Formula = Range(strTemp & strRow).Value
    Next
End Sub
 
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:

Select allOpen in new window

 

by: patrickabPosted on 2009-07-30 at 15:46:08ID: 24985056

I'm not sure why you have given a different lot of VBA - I'm afraid that's lost on me. Anyhow attached it a new file that allows you to specify the threshhold value whilst the macro is running.

Hope it helps.

Patrick

 

by: patrickabPosted on 2009-07-31 at 03:20:19ID: 24987507

The attached file is rather better...

 

by: ceneiqePosted on 2009-08-01 at 08:42:52ID: 24995717

Yes patrickab, compare-test-o8 is definitely a better solution.

Thanks aikimark for the reply in the beginning but the macro doesn't work - even after deleting one of the 2 end statements : With .Sheets("Sheet1")
so i can't allocate any points to you.

 

by: ceneiqePosted on 2009-08-01 at 08:47:57ID: 31610513

It would be good if you could also show the results (side by side ) for each threshold number that i put in.

ie. Result1 Header1   Result2 Header2

Maybe can add an inbox when i indicate a threhold the second time ,
"Do you wish to show previous threhold result?"
Type in Y or N

if one type Y - then the result2 header2 will appear after Result1 header1
else it will remain as result1 header1

so on......

but of course, this solution still fulfill except that one has to copy the results somewhere else if he has to compare the results of different threshold.

 

by: aikimarkPosted on 2009-08-01 at 09:11:05ID: 24995789

No problem.  My posted code was only meant provide your macro with the ability to reside in a static (read only) workbook and process any other workbook.  Patrickab was well on his way to posting the comparison code.

 

by: ceneiqePosted on 2009-08-01 at 09:14:09ID: 24995797

hi aikimark, glad you understand.

You might be interested in another question:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24470479.html

Thanks !

 

by: patrickabPosted on 2009-08-01 at 09:26:18ID: 24995837

ceneiqe,

>It would be good if you could also show the results (side by side ) for each >threshold number that i put in.
>ie. Result1 Header1 Result2 Header2

>Maybe can add an inbox when i indicate a threhold the second time ,
>"Do you wish to show previous threhold result?"
>Type in Y or N - if one type Y - then the result2 header2 will appear after >Result1 header1
>else it will remain as result1 header1

>so on......
>but of course, this solution still fulfill except that one has to copy the results >somewhere else if he has to compare the results of different threshold.

All easily done and I am sure it would be good, but as you have awarded a B grade I have no intention of spending any more time on this question.

Patrick

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...