VBA, Check only selected betting row with entire results

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000

Hi,


I got results in the columns C:P (R1 Through R14)
I got betting sets in the columns S:AF (B1 Through B14)

Bit complicate, I want to check any "1" betting ROW with entire results

For now I am using the formula which check if find grater than 9
Formula is in the cell Q6 and copied to down
Code:
=IF(SUMPRODUCT(--($S$6:$AF$6=C6:P6))>9,SUMPRODUCT(--($S$6:$AF$6=C6:P6)),"")

What is the problem I need to change formula every time I want to check desire row

I require VBA solution, which can give me an input option where I can enter desire combi nº is shown in column R and macro could populate the result in column Q

Please need help with this...

Example results in column Q are shown by above formula


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAG
1
2
3
4
5R1R2R3R4R5R6R7R8R9R10R11R12R13R14EMCombi nB1B2B3B4B5B6B7B8B9B10B11B12B13B14
6X11121212X11X11111211X1122111
7XX21XX1121X211221211X1212X211
8X11121212X11X1321X211X2212X12
9211X21X11221111141XX22X11111X12
101X1X11211XXX11512X12121X21X1X
11X2XX2X112111126X1X2111X1X2221
12X112111211X1X172111X1X1X2211X
131XX21X111211X182XXX1211XXXX2X
141112XXX1XX1XXX9X22X1122X11222
151XX11111X112X1101111X21X211X1X
16X1X212XXX111XX11X111XX12221111
1711X121X11121X11222XXX12111121X
1811111X11122X111013X112X222112X11
19X11XX1111211XX1412XX12X11XXXXX
20111121XX12X1X21511X11XXX12X22X
211112211X1211X116121122211111XX
2221X11X1112111217X211X2X21X12X2
231111121121XXX118X1X11212212111
24X11211211X111X1911X1122211X11X
251111X1111111112021X21221222X1X
26X1111211XX11X1212111X2X21XXX21
2712XXXX12111X11221X121X1111X1X1
28111212XXXX1X1X23X21221X1212211
29111221X1X121X224111XXX1111XX1X
30111X111X11X1122512X12121X1222X
31111X111111111110262X22X212122211
321X11211XXX1X212721X1111X11X1X1
332211X1X21221X128211X2X11X12X2X
341X12111111X1X129X12221XX2111X1
3521112X1XX11XX1301211X122XX2X1X
361XX2112X11X12X31111XX11211X1X1
37X111111112XXXX32X12X2111111X1X
38X211XX1112X11133X22112112X1XXX
39X12121XXXXX112341112212X1X1221
40111XX12X121XX135221221112X2X22
41XXX11X1111XX1136XXX11XX21112X2
422X21X1X11X12213712XX1X211X111X
43XX12X121111121381X1X2112X12111
44XX1X1111X1211X39121X1121X12112
4511X11211111X1140XX21111111111X
461111X2211111X14111212211221112
472X11111X1111X14211112221XXX2X1
48121X212111111143212X11X1XXX221
49X1X12121X2XX21441111XX21X1X121
50X1111X11111112451X22X2121X11X1
51
sheet1


Thank you in advance

Regards,
Kishan
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi,

Searching in MrExcel, I found how to put formula in VBA the code below fill formula in the column Q and after it leave the value, it is working ok.

Code:
Sub FillFormlaInQ()
    
    Dim lngLastRow As Long
    lngLastRow = Cells(Rows.Count, "C").End(xlUp).Row

    Range("Q6:Q" & lngLastRow).Formula = "=IF(SUMPRODUCT(--($S$6:$AF$6=C6:P6))>9,SUMPRODUCT(--($S$6:$AF$6=C6:P6)),"""")"
    Range("Q6:Q" & lngLastRow) = Range("Q6:Q" & lngLastRow).Value
    
End Sub

I tried modifying following code to get row number from cell Q2

Code:
Sub FillFormulaColumnInQ_UsingRowNumber_FromCellValue()
    
    
    Dim RN As Long, lngLastRow As Long
    lngLastRow = Cells(Rows.Count, "C").End(xlUp).Row
    
    RN = Worksheets("Sheet1").Cells(2, "Q").Value
    

    
    Range("Q6:Q" & lngLastRow).Formula = "=IF(SUMPRODUCT(--($S$RN:$AF$RN=C6:P6))>9,SUMPRODUCT(--($S$RN:$AF$RN=C6:P6)),"""")"
    Range("Q6:Q" & lngLastRow) = Range("Q6:Q" & lngLastRow).Value
    
End Sub

but it seems does not work it gives error 1004 and highlight following line

Code:
Range("Q6:Q" & lngLastRow).Formula = "=IF(SUMPRODUCT(--($S$RN:$AF$RN=C6:P6))>9,SUMPRODUCT(--($S$RN:$AF$RN=C6:P6)),"""")"

First I need help how can be applied the cell value in the code to get row number

Secondly is it possible instead of filling row number can I get VBA with input box where I can insert any combi nº value from Column R may be


Regards,
Kishan
 
Last edited:
Upvote 0
Hi,

I think May it is not possible to create input box to get work with combi nº

May someone can help to get row number is shown in red from cell Q2 it will be Ok, and how can be applied in VBA


Code:
    Range("Q[B][COLOR=#ff0000]6[/COLOR][/B][COLOR=#000000]:Q" & lngLastRow).Formula = "=IF(SUMPRODUCT(--($S$[/COLOR][COLOR=#ff0000][B]6[/B][/COLOR][COLOR=#000000]:$AF$[/COLOR][B][COLOR=#ff0000]6[/COLOR][/B][COLOR=#000000]=C6:P6))>9,SUMPRODUCT(--($S$[/COLOR][B][COLOR=#ff0000]6[/COLOR][/B][COLOR=#000000]:$AF$[/COLOR][COLOR=#ff0000][B]6[/B][/COLOR][COLOR=#000000]=C6:P6)),"""")  [/COLOR]

Thank you in advance

Regards,
Kishan
 
Upvote 0
Hi Kishan,

You're more or less right. RN is a row number variable, but the code is instead entering the text "RN" as part of the formula, so it is trying to look at Cell $AF$RN, which of course isn't a thing!

Try this:

Code:
Range("Q6:Q" & lngLastRow).Formula = "=IF(SUMPRODUCT(--($S$" & RN & ":$AF$" & RN & "=C6:P6))>9,SUMPRODUCT(--($S$" & RN & ":$AF$" & RN & "=C6:P6)),"""")

Cheers
JB
 
Upvote 0
A solution using formulas

Try


[TABLE="class: grid"]
<tbody>[TR]
[TD="bgcolor: #DCE6F1"][/TD]
[TD="bgcolor: #DCE6F1"]
A
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
1
[/TD]
[TD]
Desired Comb​
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
2
[/TD]
[TD]
6
[/TD]
[/TR]
</tbody>[/TABLE]


Enter the desired combination in A2

Change the formula in Q6 to
=IF(SUMPRODUCT(--(INDEX(S:AF,A$2,0)=C6:P6))>9,SUMPRODUCT(--(INDEX(S:AF,A$2,0)=C6:P6)),"")
copy down

Hope this helps

M.
 
Last edited:
Upvote 0
Hi Kishan,

You're more or less right. RN is a row number variable, but the code is instead entering the text "RN" as part of the formula, so it is trying to look at Cell $AF$RN, which of course isn't a thing!

Try this:

Code:
Range("Q6:Q" & lngLastRow).Formula = "=IF(SUMPRODUCT(--($S$" & RN & ":$AF$" & RN & "=C6:P6))>9,SUMPRODUCT(--($S$" & RN & ":$AF$" & RN & "=C6:P6)),"""")

Cheers
JB
Hi bellman101, code is working flawless!!

Do you have idea instead of applying a row number in the cell Q2 does it is possible to have input box, I mean after the code is run pop up input box where I can insert the row number?

Thank you very much for your time and help

Regards,
Kishan

 
Upvote 0


Do you have idea instead of applying a row number in the cell Q2 does it is possible to have input box, I mean after the code is run pop up input box where I can insert the row number?

Have you tried my suggestion in post 5 (no VBA)?

M.
 
Upvote 0
Yup,

replace the RN = with this:

RN = Inputbox ("What Row Number please Kishan?")

beware without error handling, your code will fail if you enter a non-numeric, or cancel or click the red x in the input box.
 
Upvote 0
A solution using formulas

Try


[TABLE="class: grid"]
<tbody>[TR]
[TD="bgcolor: #DCE6F1"][/TD]
[TD="bgcolor: #DCE6F1"]
A
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
1
[/TD]
[TD]
Desired Comb​
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
2
[/TD]
[TD]
6
[/TD]
[/TR]
</tbody>[/TABLE]


Enter the desired combination in A2

Change the formula in Q6 to
=IF(SUMPRODUCT(--(INDEX(S:AF,A$2,0)=C6:P6))>9,SUMPRODUCT(--(INDEX(S:AF,A$2,0)=C6:P6)),"")
copy down

Hope this helps

M.
Hi Marcelo Branco, I never thought it could be done this way it is very practical, brilliant idea!!

I like your formula non-vba solution!!

Thank you very much for your time and help

Regards,
Kishan


 
Upvote 0
Yup,

replace the RN = with this:

RN = Inputbox ("What Row Number please Kishan?")

beware without error handling, your code will fail if you enter a non-numeric, or cancel or click the red x in the input box.
Thanks bellman101, for giving a code, which enter a row number via input box, it is very perfect!!

Thank you once again for you help

Regards,
Kishan

 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top