Fill Cells with Value if number falls between a certain range

SkiliedSin

Board Regular
Joined
May 7, 2018
Messages
51
Office Version
  1. 365
Hey guys,

I was wondering if you guys could help me with this!

For example if the number falls between 0-15, to fill the cells adjacent to it with 1 "Name" and 2 "Age" (so 3 cells total)
16-30, to fill the cells adjacent to it with 2 "Name" and 4 "Age" (so 6 cells total),
and so forth and so on up until 80-95?

Would this be possible?
 
Hey, sorry for all the confusion.

https://imgur.com/a/sQ8ETbO

Here is what I want it to look like, thank you.

Hmm! I am trying to decide if you really want us to provide you with a solution or not.:eek: Your original post said this...
For example if the number falls between 0-15, to fill the cells adjacent to it with 1 "Name" and 2 "Age" (so 3 cells total)
16-30, to fill the cells adjacent to it with 2 "Name" and 4 "Age" (so 6 cells total),
and so forth and so on up until 80-95?
In the picture you posted, you showed 2 Names and 1 Age for 15-30 (NOT 16-30 like you posted in your first message), not 2 Names and 4 Ages like you said in your first post for what I assume should be the same (similar?) range. You did not show what you want in your picture for 0-15 (which I guess should now be 0-14 maybe?) so who know what that should actually be. Then, for the next range 31-45 you show 4 Ages and 4 Names which does not "flow" sequentially from the previous ranges, so I am not sure how you expected us to guess that given that you said (in your first post) "and so forth" for the unspecified ranges. And, of course, since this range does not flow sequentially from the previous range, who knows what should apply for the next ranges. Why don't you make this easier for us and post a table showing the (actual) ranges (all of them) and the number of Ages and Names for each range.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Sorry, the image I posted was just a quick example. It wasn't accurate at all. I would have just changed the ranges myself as I did not want to keep you waiting. My apologies.

This is the actual range:
https://imgur.com/a/yDwkZ3W

Thanks again and sorry for the confusion.
 
Upvote 0
Assuming your values are in Column A starting on Row 2 (I am assuming Row 1 has header text in it), give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub AgesAndNames()
  Dim Cell As Range
  For Each Cell In Range("[B][COLOR="#FF0000"]A2[/COLOR][/B]", Cells(Rows.Count, "A").End(xlUp))
    Select Case Cell.Value
      Case 1 To 15: Cell.Offset(, 2).Resize(, 2) = Array("Age", "Name")
      Case 16 To 30: Cell.Offset(, 2).Resize(, 3) = Array("Age", "Age", "Name")
      Case 31 To 45: Cell.Offset(, 2).Resize(, 5) = Array("Age", "Age", "Age", "Name", "Name")
      Case 46 To 60: Cell.Offset(, 2).Resize(, 6) = Array("Age", "Age", "Age", "Age", "Name", "Name")
      Case 61 To 75: Cell.Offset(, 2).Resize(, 8) = Array("Age", "Age", "Age", "Age", "Age", "Name", "Name", "Name")
      Case 76 To 90: Cell.Offset(, 2).Resize(, 9) = Array("Age", "Age", "Age", "Age", "Age", "Age", "Name", "Name", "Name")
      Case 90 To 100: Cell.Offset(, 2).Resize(, 10) = Array("Age", "Age", "Age", "Age", "Age", "Age", "Name", "Name", "Name", "Name")
    End Select
  Next
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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