Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Fill non-sequential cells with dates

Posted on 2013-12-23
15
Medium Priority
?
541 Views
Last Modified: 2013-12-23
Howdy experts, and seasons greetings to all.....

I have a calendar/time sheet that was passed on to me. It has run out of current dates and I need to refill it.
The cells are non-sequential as you can see by the attached.

Can anyone provide a formula or script to fill them as needed to continue using for the future?

thanks
perpetual-time-sheet.xlsx
0
Comment
Question by:SeaSenor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 5
15 Comments
 
LVL 35

Expert Comment

by:mvidas
ID: 39736292
Hi SS,

It looks like your attachment is simply an image of a spreadsheet pasted over an actual spreadsheet?

What I did is remade a mockup of your sheet, using formulas. All I had to do was set a date for the first date cell, then the rest of that row was just =B2+1, =D2+1, etc. Then I just copied that block into the next week's position, and did =B2+7 and kept the +1 formulas the same. Then I just copied week 2 into week 3, week 4, week 5, without having to update anything. It is very easy to add more time to it, just copy more rows and delete any leftover actual data.

Here's what I made to demonstrate this.
Matt
perpetual-time-sheet2.xlsx
0
 
LVL 8

Author Comment

by:SeaSenor
ID: 39736321
thanks Matt... sorry about the image.
Here is an actual sheet.

that may be workable.
It's not exactly what I was looking for though.
When I got the spreadsheet a few years ago, I found a formula that filled/populated them all the way through the end of the current sheet. (about 2-3 years at that time)
Since them, I have copied/pasted several more years of the same formatting for future use and need to fill the date cells.
I can't find that formula now for some reason....but I seem to remember it being a fill type formula.
PeretualSheet.xlsx
0
 
LVL 26

Expert Comment

by:pony10us
ID: 39736325
One change I would make to the formulas would be to verify that there is a value.

In cell D2:      =if(b2<>"",b2+1,"") and carry it through for the week (f2, h2, j2, l2 and n2)
In cell b11:    =if(b2<>"",b2+7,"") and carry it through column B cells  (b20 and b29)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Author Comment

by:SeaSenor
ID: 39736330
Pony10us
nice catch...

that may already be in the (newer) version of the attached files.
0
 
LVL 35

Expert Comment

by:mvidas
ID: 39736360
If you press F5 (goto) then press Special, you can select "constants" to select just the dates. But you're still stuck with populating them.

You could use that to your advantage with a quick macro though, utilizing the formula (for easy updating later)
    Dim RG As Range
    Set RG = Cells.SpecialCells(xlCellTypeConstants, 1)
    Intersect(RG, Columns("E:O")).FormulaR1C1 = "=RC[-2]+1"
    Intersect(RG, Range("C11:C8741")).FormulaR1C1 = "=R[-9]+7"

Open in new window

0
 
LVL 26

Assisted Solution

by:pony10us
pony10us earned 1000 total points
ID: 39736473
You could always use something like this macro:

Sub AddDates()
Srow = 2
BeginDate = DateSerial(2013, 12, 30)
EndDate = DateSerial(2014, 12, 31)
NewDate = BeginDate
Do Until NewDate > EndDate
    Cells(Srow, "B").Value = NewDate
    For i = 1 To 6
        Cells(Srow, "B").Offset(0, i).Value = NewDate + i
    Next i
    NewDate = NewDate + 7
    Srow = Srow + 9
Loop
End Sub

Open in new window


You would have to set your BeginDate and EndDate or set it up to ask for those dates.
0
 
LVL 8

Author Comment

by:SeaSenor
ID: 39736511
pony10us

ran the macro....

it filled in about 3 columns over then down.
also dates jumped by two days, not sequentially.

can you run it against a copy of the attached file and see what mods to make?
0
 
LVL 35

Expert Comment

by:mvidas
ID: 39736520
I tested my macro on your workbook, and it took less than a second to run. Is there something missing from that? I could have it prompt you for a initial date, and then put that value into cell C2 for you if you wanted.
Or if you wanted the macro to leave you with a date value, instead of a date formula, simply put "RG.Value = RG.Value" as a last line in it.
0
 
LVL 26

Expert Comment

by:pony10us
ID: 39736540
mvidas,

That would be about correct for time.  It is very quick. There are however 2 issues with it. The first is easy enough to fix. Just change Lines 7 and 9 to be "C" instead of "B".

The second is a little more challenging.  Since it is using merged cells on the Date row I did not account for every other column. I am looking at that now but if you have any suggestions please feel free to provide them.
0
 
LVL 35

Expert Comment

by:mvidas
ID: 39736549
For the "every other column" thing, change your offset from Offset(0, i) to Offset(0, i * 2)
0
 
LVL 35

Accepted Solution

by:
mvidas earned 1000 total points
ID: 39736565
I hadn't tested your macro until now, so I should have refrained from posting the suggestion. The merged cell property of column C prevents the *2 from working (as the offsets really would need to be 1,3,5,7,etc). For your macro to work an easy fix would be:
Sub AddDates()
Dim Srow As Long, BeginDate As Long, EndDate As Long, NewDate As Long, i As Long
Srow = 2
BeginDate = DateSerial(2013, 12, 30)
EndDate = DateSerial(2014, 12, 31)
NewDate = BeginDate
Do Until NewDate > EndDate
    Cells(Srow, 3).Value = NewDate
    For i = 1 To 6
        Cells(Srow, 3 + i * 2).Value = NewDate + i
    Next i
    NewDate = NewDate + 7
    Srow = Srow + 9
Loop
End Sub

Open in new window

0
 
LVL 26

Expert Comment

by:pony10us
ID: 39736608
That does it.  I had tested it on a blank worksheet and it worked but when SeaSenor said it didn't I noticed the merged cells.  I usually avoid that feature so was having trouble with it.
0
 
LVL 8

Author Comment

by:SeaSenor
ID: 39736662
Thank you all... it works well.

I had to change the Srow to a different starting point, and the end date to 12/31/2050
took about 20 seconds on a pretty fast computer.

Now I'm good past retirement (hopefully!!!)
0
 
LVL 8

Author Closing Comment

by:SeaSenor
ID: 39736701
Well Done!!!
0
 
LVL 26

Expert Comment

by:pony10us
ID: 39736710
Glad to help AND learn at the same time.  :)
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question