View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
HUGO HUGO is offline
external usenet poster
 
Posts: 30
Default VBA for Month and Quarters Output

One issue I've found with this subroutine is that if the starting date is the
last month of a quarter, it skips that quarter. So for example if the
starting date is "June-xxxx", the output will be "Jun-xxxx, Jul-xxxx,
Aug-xxxx, Sep-xxxx, Q3-xxxx, Oct-xxxx, etc.", instead of "Jun-xxxx, Q2-xxxx,
Jul-xxxx, Aug-xxxx, Sep-xxxx, Q3-xxxx, Oct-xxxx, etc."

Any thoughts?

--
Hugo


"Rick Rothstein" wrote:

Something like this maybe?

Sub DatesWithQuarters()
Dim X As Long, Col As Long
Dim StartDate As Variant, Duration As Variant
Col = 5 ' This is the starting column for the list
StartDate = InputBox("Tell me the starting month and 4-digit year")
Duration = InputBox("How many months should be listed?")
If IsDate(StartDate) And Len(Duration) 0 And _
Not Duration Like "*[!0-9]*" Then
If Duration 0 Then
StartDate = CDate(StartDate)
For X = 0 To Duration - 1
Cells(1, Col).NumberFormat = "mmm-yyyy"
Cells(1, Col).Value = DateAdd("m", X, StartDate)
If Month(DateAdd("m", X, StartDate)) Mod 3 = 0 And X 0 Then
Col = Col + 1
Cells(1, Col).NumberFormat = "@"
Cells(1, Col).Value = Format(DateAdd("m", X, _
StartDate), "\Qq-yyyy")
End If
Col = Col + 1
Next
End If
End If
End Sub

--
Rick (MVP - Excel)


"Hugo" wrote in message
...
Ryan,

Thanks for your help. That is not quite what I am looking for, but
perhaps
it can be a good starting place.

I am really trying to get someting where the months and quarters are in
the
output (i.e. in one row there will be an output of three months, followed
by
the fiscal quarter that describes those three months, followed by the next
three months, followed by the quarter that describes those next three
months,
etc.)
--
Hugo


"ryguy7272" wrote:

How about this:
Sub BeginMonth()

Dim Mth As String
Dim Nbr As Long

Mth = InputBox("Please enter a beginning month.")

Range("C5").Select
ActiveCell = Mth

Nbr = CLng(Application.InputBox _
(prompt:="Please enter total number of months.", Type:=1))

Range("Z1").Select
ActiveCell = Nbr

Range("C5").Select
Selection.AutoFill Destination:=Range _
(Selection, Selection.Resize(1, Nbr))

End Sub

HTH,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking
''Yes''.


"Hugo" wrote:

Hi,

I am new to writing in VBA, but I would like to write a function, where
the
inputs are a start date and an end date (month&year), and the output is
a
range in a single row of an indefinite number of columns (to be
determined by
how muhc time is between the starting date and the ending date). I
would
like the output to be in the form of showing the month and year, and at
the
end of every fiscal quarter showing the quarter and year. For example
the
output would look like the following, where a comma shows where a break
between cells in a row occurs:

"Jan-2009, Feb-2009, Mar-2009, Q1-2009, Apr-2009,..."

Any tips would be greatly appreciated. I assume I will have to write
this
as a function not a subroutine, but would appreciate hearing
suggestions.

Thanks!
--
Hugo