Formula not working......and I can't see why!

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
270
Office Version
  1. 365
Platform
  1. Windows
Cells B4 and B5 on my worksheet allow the user to enter a year and period. So, typically they'll enter 2021 in B4 and 7 in B5 (relating to period 7 in 2021, i.e July).

I have this formula in B6;
Code:
=B4&IF(B5<"10","0"&B5,B5)

which drives some SQL code in my macro. In the above example, 202107 is correctly returned.

However, if they enter 2021 in B4 and 10 in B5, my SQL code returns no data and I can see why - in B6, my formula isn't working, it's returning 2021010.

What am I doing wrong? it works for 1-9 but not 10 (and presumably 11 and 12)!!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

B
C
D
8​
08​
08​
9​
09​
09​
10​
010​
10​
11​
011​
11​


B
C
D
8​
=IF(B8<"10","0"&B8,B8)​
=IF(B8<10,"0"&B8,B8)​
9​
=IF(B9<"10","0"&B9,B9)​
=IF(B9<10,"0"&B9,B9)​
10​
=IF(B10<"10","0"&B10,B10)​
=IF(B10<10,"0"&B10,B10)​
11​
=IF(B11<"10","0"&B11,B11)​
=IF(B11<10,"0"&B11,B11)​
 
Upvote 0
Solution
"10" mean Excel reads this as text, not a number. Maybe this works?
Excel Formula:
=B4&IF(VALUE(B5)<10,"0"&B5,B5)
 
Upvote 0
Hi, you could also try this alternative in B6.

Excel Formula:
=B4&TEXT(B5,"00")
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

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