MATCH / INDEX in VBA Con't

ron.bo

Board Regular
Joined
Mar 15, 2011
Messages
129
Office Version
  1. 2007
Platform
  1. Windows
I started with needing help creating a routine using Index and Match. What I need to do is;

1. Get input from a user input box = Amt
2. Starting at D4 (with range D4..O4) check D4 and if it =1, then
3. formula in D10 = INDEX(DATA!$A$5:DATA!$BB$200,MATCH($B8,DATA!$A$5:$A$200,0),MATCH(D$6,DATA!$A$5:$BB$5,0)) * Amt, then
4. Copy the formula down to D46 then change to value (rather than leaving as formula)
5. Check the next cell to the right of D4 (E4) and if it =1, repeat
6. Loop until the next cell to the right <> 1.

Notes:
1. The formula in the next cell (E4) = INDEX(DATA!$A$5:DATA!$BB$200,MATCH($B8,DATA!$A$5:$A$200,0),MATCH(E$6,DATA!$A$5:$BB$5,0)) * Amt (Note the last MATCH value changed from D$6 to E$6 and must do that for each corresponding formula.
2. I need the routine to start at D4 and loop through O4 looking for any cell in row 4 that has a 1 and then start at that column and continue until the next cell in row 4 <>1.

Andrew P. help with;

Sub Test()
Dim Amt As Variant
Dim Cell As Range
Amt = InputBox("Enter amount")
If Amt = "" Then Exit Sub
For Each Cell In Range("D4:O4")
If Cell.Value = 1 Then
With Cell.Offset(6).Resize(37)
.FormulaR1C1 = _
"=INDEX(DATA!R5C1:DATA!R200C54,MATCH(R[-2]C2,DATA!R5C1:R200C1,0),MATCH(R6C,DATA!R5C1:R5C54,0))*" & Amt
.Value = .Value
End With
Else
Exit Sub
End If
Next Cell
End Sub

The problem is that it does not work with Note 2. i.e. if D4's value is not 1 but E4 is 1, the code does not execute. In this case I need for it to start in E4 and continue until the next cell in D4..O4 does not contain 1.

Some examples are as follows;

In the range D4..O4 the value can be either 1 or 2. What I need the routine to do is to check each cell in the range starting at D4 and continue until the next cell does not =1

D4 E4 F4 G4 H4 I4 J4 K4 L4 M4 ... O4

a. 1 1 1 1 1 1 2 2 2 2 ... 2
b. 1 1 2 2 2 2 2 2 2 1 ... 1
c. 2 2 2 2 2 2 2 2 1 1... 1

In example a the routine would start at D4 and run through I4.

In example b the routine would start at D4 and run through E4.

In example c the routine would start at L4 and run through O4.


Thanks,
Ronbo
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,224,525
Messages
6,179,319
Members
452,905
Latest member
deadwings

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