Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Formula Assistance for Variable No. of Cells in a Column

0

I'm currently working on an electrical usage billing period spreadsheet where I import the usage data for each day in a given month. The first column has the date for each day of the month (12/21/2022  12:00:00 AM, for example) listed for the given billing period, but every month has a different number of days. Sometimes there are 30 rows in the column for days 1-30, 31 rows for days 1-31, etc. I am using the formula:
=TEXT(C10,"mm/dd/yy")&" - "&TEXT(C40,"mm/dd/yy")
to show the specific dates for the billing period, but "C40" can change to C39, C41, etc., depending on the number of days in the month.  I've been changing "C40" in the formula manually for each billing period. Is there a formula that I can use that automatically adjust "C40", in this example, to be variable depending on how many items (days) are in the column? I'm using COUNTA to get the total number of rows with data in the column C10 to C45 but don't know how to use that in the formula shown above. Do you happen to know of a way for C40 to be variable depending on how much data is in a column?

Thanks in advance for any help you can offer!

Answer
Discuss

Answers

0
Selected Answer

Hi Wireedm anf welcome to the Forum

If you want a combine a variable start and end date, you could use the Excel functions MAX (maximum) and MIN (minimum) on the possible but variable range of cells, with your TEXT conversion. Try this (changes in bold):

=TEXT(MIN(C10:C40), "mm/dd/yy")  & " - " & TEXT(MAX(C10:C40), "mm/dd/yy")
 

You'll get results like "02/01/23 - 02/28/23" (for February 2023, with cells C10 to C37 showing February dates).

Hope this helps- if so, please remember to mark this Answer as Selected.

Discuss

Discussion

Perfect, thank you!!
wireedm (rep: 2) Jan 26, '23 at 5:34 am
Great! Thanks for selecting my Answer.
John_Ru (rep: 6142) Jan 26, '23 at 7:52 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login