Solved

Index ranges by 1

Posted on 2013-11-26
7
102 Views
Last Modified: 2013-11-26
Folks,
In my worksheet Range A4 = Range H2
Range H2 = Today()
I would like to be able to increase ranges A5 = A9 by A4+1
In other words if the date in A4 = 11/26/2013 the the dates in A5:A9 would be incremented by 1 day such that A5 = 11/27/2013...
0
Comment
Question by:Frank Freese
  • 4
  • 3
7 Comments
 
LVL 23

Expert Comment

by:NBVC
ID: 39678827
Try:

in A5:

=$A$4+ROWS($A$5:$A5)

copied down
0
 

Author Comment

by:Frank Freese
ID: 39678887
Whoops...my mistake. I'm not going down...going across. I'll try substitute Column for Row?
Also need in VBA format
0
 
LVL 23

Expert Comment

by:NBVC
ID: 39678929
The formula would be:

=$A$4+COLUMNS($A$5:A$5)

simple macro:

Sub CummulativeDate()
For i = 2 To 6
 Cells(4, i) = Cells(4, 1) + i - 1
Next i

End Sub

Open in new window

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:Frank Freese
ID: 39679035
Here's the code I'm using in my procedure:

Dim NextCell As Long
Range("A4") = Range("H2")
For NextCell = 2 To 8
    Cells(4, NextCell) = Cells(4, 1) + NextCell - 1
Next NextCell

Open in new window

What happens is that the first cell (B4) is correctly populated, but then I drop completly out of the sub to another sub and never get to the NextCell
0
 

Author Comment

by:Frank Freese
ID: 39679056
I recorded a macro then copy the below code to my subprocedure and it worked.
Range("B4").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]+1"
    Range("B4").Select
    Selection.AutoFill Destination:=Range("B4:H4"), Type:=xlFillDefault
    Range("B4:H4").Select

Open in new window

Can I award points for being "close"?
0
 
LVL 23

Accepted Solution

by:
NBVC earned 500 total points
ID: 39679141
You can replace all of that with:

With Range("B4")
    .FormulaR1C1 = "=RC[-1]+1"
    .AutoFill Destination:=Range("B4:H4"), Type:=xlFillDefault
End With

Open in new window

so that you eliminate the use of Select (which is known to be inefficient and redundant).
0
 

Author Closing Comment

by:Frank Freese
ID: 39679309
good job! thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now