Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50167

Ranges in selection and arrays

$
0
0
Hi everyone,

I have this following code i need help with

Code:

Sub userDef()
    Dim cNum As Long
    Dim cSel As Range
    Dim cArray() As Double
    Dim j As Integer

    j = 0
    ReDim cArray(0)
   
    cNum = Application.InputBox("Number of columns:")
    For i = 1 To cNum
        Set rSel = Application.InputBox("Select " & i & " column(s) range", Type:=8)
        Set cSel = Application.InputBox("Select " & i & " cell(s) to compare", Type:=8)
        If rSel Is Nothing Then
            MsgBox "No cell selected"
            Exit Sub
        Else
            cArray(j) =
            j = j + 1
            ReDim Preserve cArray(j)
        End If
    Next i
End Sub

The code is unfinished because i don't know how to convert the first range selection (ex: A to E would be 1 to 5) and store it for later use. I would also want to store the cell range(i, j) of the second selection in another array.

Here's the code i will use with the arrays

Code:

Sub doArrange()



    Dim rw, col As Integer


    rw = 5


nxtChk:
  a = Math.Round(Cells(rw, 11).Value, 2)
  b = Math.Round(Cells(rw, 26).Value, 2)
  c = Math.Round(Cells(rw + 1, 26).Value, 2)
  d = Math.Round(Cells(rw + 1, 11).Value, 2)
  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 = 1 To 11
        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 = 16 To 26
        Cells(rw, col).Insert shift:=xlDown
        Next col
  End If


    If rw > 5 And b = 0 Then Exit Sub
    rw = rw + 1


GoTo nxtChk


End Sub

Thanks in advance.

Viewing all articles
Browse latest Browse all 50167

Trending Articles