Results 1 to 10 of 10

Compare multiple cells at the same time

Threaded View

  1. #1
    Registered User
    Join Date
    04-28-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2013
    Posts
    19

    Compare multiple cells at the same time

    If you could help me with my problem anaylising multiple cells at the same time, i would be appreciated.

    Here's what i mean from the code i have.

    Option Base 1
    Sub userDef()
        Dim cNum As Long
        Dim stColArray(), lstColArray() As Variant
        Dim cRowArray(), cColArray() As Variant
        Dim cSel, rSel As Range
        Dim rw, col, j, mvSt1, mvEnd1, mvSt2, mvEnd2 As Integer
    
        j = 1
        
        cNum = Application.InputBox("Number of columns:")
        ReDim rStArray(cNum)
        ReDim stColArray(cNum)
        ReDim lstColArray(cNum)
        ReDim cRowArray(cNum)
        ReDim cColArray(cNum)
        For c = 1 To cNum
            Set rSel = Application.InputBox("Select " & c & " table(s)", Type:=8)
            Set cSel = Application.InputBox("Select " & c & " cell(s) of " & c & " table", Type:=8)
            If rSel Is Nothing Then
                MsgBox "No cell selected"
                Exit Sub
            Else
                stColArray(j) = rSel.Column
                lstColArray(j) = rSel.Columns(rSel.Columns.Count).Column
                cRowArray(j) = cSel.Row
                cColArray(j) = cSel.Column
                j = j + 1
            End If
        Next c
        
        
        j = 1
        x = 1
        y = 2
        rw = cRowArray(j)
        
    nxtChk:
      
      a = Math.Round(Cells(rw, cColArray(x)).Value, 2)
      d = Math.Round(Cells(rw + 1, cColArray(x)).Value, 2)
      mvSt1 = stColArray(x)
      mvEnd1 = lstColArray(x)
    
      b = Math.Round(Cells(rw, cColArray(y)).Value, 2)
      c = Math.Round(Cells(rw + 1, cColArray(y)).Value, 2)
      mvSt2 = stColArray(y)
      mvEnd2 = lstColArray(y)
      
      stDevAB = Math.Sqr((((b - ((b + a) / 2)) ^ 2) + ((a - ((b + a) / 2)) ^ 2)) / 2)
      stDevAC = Math.Sqr((((c - ((c + a) / 2)) ^ 2) + ((a - ((c + a) / 2)) ^ 2)) / 2)
      stDevBA = Math.Sqr((((a - ((a + b) / 2)) ^ 2) + ((b - ((a + b) / 2)) ^ 2)) / 2)
      stDevBD = Math.Sqr((((d - ((d + b) / 2)) ^ 2) + ((d - ((d + b) / 2)) ^ 2)) / 2)
      stErrAB = stDevAB / Math.Sqr(2)
      stErrAC = stDevAC / Math.Sqr(2)
      stErrBA = stDevBA / Math.Sqr(2)
      stErrBD = stDevBD / Math.Sqr(2)
      
      If a > 0 And b > 0 Then
        chisqrAB = ((b - a) - 0.05) ^ 2 / a
        p_val_AB = WorksheetFunction.ChiDist(chisqrAB, 1)
        chisqrAC = ((c - a) - 0.05) ^ 2 / a
        p_val_AC = WorksheetFunction.ChiDist(chisqrAC, 1)
        chisqrBA = ((a - b) - 0.05) ^ 2 / b
        p_val_BA = WorksheetFunction.ChiDist(chisqrBA, 1)
        chisqrBD = ((d - b) - 0.05) ^ 2 / b
        p_val_BD = WorksheetFunction.ChiDist(chisqrBD, 1)
      End If
     
      If a > 0 And stDevAB > stDevAC And stErrAB > stErrAC And p_val_AB < p_val_AC Then
            For col = mvSt1 To mvEnd1
            Cells(rw, col).Insert shift:=xlDown
            Next col
      ElseIf b > 0 And stDevBA > stDevBD And stErrBA > stErrBD And p_val_BA < p_val_BD Then
            For col = mvSt2 To mvEnd2
            Cells(rw, col).Insert shift:=xlDown
            Next col
      End If
    
    
        If rw > 5 And b = 0 Then
        y = y + 1
        rw = cRowArray(j) - 1
        End If
        If rw > 5 And b = 0 And y > cNum Then Exit Sub
        rw = rw + 1
    
    GoTo nxtChk
        
    End Sub
    I've attached the sample workbook too.

    13081715551.xlsm

    Variable a and d will be the fixed from the first selected cell.
    Variable b and c will have values from the other selected cells which i want to compare against a and d.
    If you have 3 selected cells the comparision i want is cell 1 vs cell 2 and cell 1 vs cell 3 all at the same time so that the line that will be inserted will be equally distribuited.

    Thanks for your patience.
    Last edited by fgq; 08-19-2013 at 01:19 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Compare multiple cells to see if they match exactly
    By redwine in forum Excel General
    Replies: 12
    Last Post: 08-24-2016, 11:28 PM
  2. [SOLVED] How to compare time values in different cells - type mismatch
    By TC1980 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-05-2013, 10:13 AM
  3. macro to compare time between two cells if time matches output in third cell
    By kshitij_dch in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2012, 07:09 AM
  4. to compare data in multiple cells
    By magendiran.thiru in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 11-21-2010, 04:12 AM
  5. how to compare if multiple cells are equal
    By evanhughes in forum Excel General
    Replies: 13
    Last Post: 02-02-2010, 02:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1