Saltar al contenido
View in the app

A better way to browse. Learn more.

Ayuda Excel

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Vba combinaciones añadir condicion

publicado

Hola a todos. He tratado de añadir una nueva condicion a mi codigo de combinaciones pero en cada intento, solo saco errores, o no produce ningun resultado.

Este codigo produce una lista de combinaciones de 6 numeros y puedo controlar cuantos primos y pares como tambien la suma de cada combinacion.

La condicion que deseo añadir ahora es Columna "Q" - col "L" si el resultado esta comprendido entre los numeros minimo de la celda E9 y el maximo de la celda E10 entonces mostrar la combinacion, de lo contrario no mostrarla.

La lista de combinaciones esta en el sheet2, y el modulo es el 1.

Quiero ser un poco mas claro, para poder recibir ayuda.

VARIABLES.

minV = valor minimo

maxV= valor maximo

Dif = diferencia

la locacion de las variables es

E9 = minV

E10=maxV

el proceso seria

Col ("Q") - Col ("L") = Dif

if Dif >= minV and Dif <=maxV then True.

es mas o menos la idea,

Gracias por la ayuda que me puedan brindar.

trato de subir mi archivo pero dice que es muy grande,

Featured Replies

publicado
  • Autor

Option Explicit

Public sumArr As Long, oddNo As Long, evenNo As Long, oddNoReq As Long, LastRow As Long, _
evenNoReq As Long, minSumValue As Long, maxSumValue As Long, lRow As Long, testRow As Long, minMaxRn As Long
Sub Combinations()
Dim rRng As Range, p As Integer
Dim vElements, vresult As Variant
Dim q As Integer
Dim b As Double
Dim exceptrange As Range 'variable for exceptions

Set exceptrange = Range("D12:D22") 'INPUT SUM EXCEPTIONS

Set rRng = Range("A1", Range("A1").End(xlDown)) 'INPUT NUMBERS TO PLAY

oddNoReq = Range("D7"): evenNoReq = Range("D6"): minSumValue = Range("D9"): maxSumValue = Range("D10")

lRow = 1: testRow = 1

p = 6: b = 1

For q = 0 To p - 1
b = b * (LastRow - q) / (p - q)
Next q

Range("E33") = b 'OUTPUT TOTAL COMBINATIONS

vElements = Application.Index(Application.Transpose(rRng), 1, 0)

ReDim vresult(1 To p)
Columns("K").Resize(, p + 15).Clear

Call CombinationsNP(vElements, p, vresult, lRow, 1, 1, exceptrange)
Exit Sub

End Sub
Sub CombinationsNP(vElements As Variant, p As Integer, vresult As Variant, lRow As Long, iElement As Integer, iIndex As Integer, XceptValues As Range)
Dim i As Integer, k As Integer

For i = iElement To UBound(vElements)
vresult(iIndex) = vElements(i)
If iIndex = p Then 'P IS THE 6 NUMBERS OR SIX COLUMNS

For k = LBound(vresult) To UBound(vresult) 'HERE IS PRODUCED THE COMBINATIONS
If vresult(k) Mod 2 <> 0 Then oddNo = oddNo + 1
If vresult(k) Mod 2 = 0 Then evenNo = evenNo + 1
sumArr = sumArr + vresult(k)
Next k


If (oddNo = oddNoReq) And (evenNo = evenNoReq) _
And (sumArr >= minSumValue) And (sumArr <= maxSumValue) _
And (LoopRow(XceptValues, sumArr)) Then

lRow = lRow + 1
testRow = testRow + 1
Range("L" & lRow).Resize(, p) = vresult 'OUTPUT COMBINATION MATCH CRITERIA
Range("S" & lRow) = sumArr 'OUTPUT SUM BY ROW
Range("W" & lRow) = Range("Q" & lRow) - Range("L" & lRow)
Range("U" & lRow) = Range("O" & lRow) - Range("N" & lRow)
Range("V" & lRow) = Range("P" & lRow) - Range("M" & lRow)
End If
End If

If iIndex <> p Then
Call CombinationsNP(vElements, p, vresult, lRow, i + 1, iIndex + 1, XceptValues)
End If
sumArr = 0
evenNo = 0
oddNo = 0

Next i
End Sub[/CODE]

este es el codigo que necesita la condition mencionada

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.