Help to Select Case with dynamic range

sbv1986

Board Regular
Joined
Nov 2, 2017
Messages
87
Hi All

I want to have a Function with select case that:
range value is range(A2: last row) and group by range(B2:lastrow) like below table have 04 group:
The code of function like this:
Code:
Funtion ()
for i = range(A2: lastrow)
select case group by range(B2:last row)
Case a = Array("B004")
'group by range (B2:last row) = "20"
Case a = Array("A002","G010")
'group by range (B2:last row) = "15"
Case a = Array("B002","B010")
'group by range (B2:last row) = "10"
Case Esle  ---> 
'group by range (B2:last row) = "7"
next i
End Function

I'm not sure how to code right to do this, please help me

Thanks./.
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]A001[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]B002[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]A002[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]B004[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]C005[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]C001[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]A010[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]B010[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]G010[/TD]
[TD]15[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Since you are looping through the values in Column A, just put the appropriate value that corresponds into Column B.

Code:
Sub FillValues()
Dim c As Range
For Each c In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
    Select Case c
        Case "B004"
            c.Offset(, 1) = 20
        Case "A002", "G010"
            c.Offset(, 1) = 15
        Case "B002", "B010"
            c.Offset(, 1) = 10
        Case Else
            c.Offset(, 1) = 7
    End Select
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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