Value from Range

Forestq

Active Member
Joined
May 9, 2010
Messages
482
Hi,

I want to put different text name for value depend on to which ranges value belong. My ranges:

0 - 15: text name: "AAAA"
6-28: text name: "BBBBB"
more than >29 : "CCCCC"

I have below code, but I know that my condition are wrong:
Code:
looking_date = ws.Range("B2").Value

if looking_date < 15 then
 ws2.Range("C2").Value = "AAAA"
Else if looking_date < 28 then
 ws2.Range("C2").Value = "BBBB"
Else
 ws2.Range("C2").Value = "CCCC"

are you able to help?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
as also Fishboy wrote, number like 2 or 3 belond to both ranges (0-15, 0-28....)
Yes, I guess this would be better:
Code:
=LOOKUP(B2,{0,16,29},{"AAAA","BBBBB","CCCCC"})
According to your VBA code, the second range starts at 16, not at 6.
And the third range starts at 29, so >= 29, not > 29?
 
Upvote 0
Don't you just need to add "betweens"

Code:
if looking_date <= 15 then
 ws2.Range("C2").Value = "AAAA"
Else if looking_date >= 16 And <= 28 then
 ws2.Range("C2").Value = "BBBB"
Else
 ws2.Range("C2").Value = "CCCC"
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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