Consulting

Results 1 to 3 of 3

Thread: Not sure how to Amend current VBA code to do one more step

  1. #1
    VBAX Contributor
    Joined
    Aug 2007
    Posts
    165
    Location

    Not sure how to Amend current VBA code to do one more step

    Hi Experts

    i have the following VBA code.....not sure how thsi can be done,,,,but i am sure it'll be a walk in the park for some of you people....

    here is the code:

    Sub MyMacro()

    Range(InputBox("Enter the end row i.e B37")).Select
    ActiveCell.Rows("1:1").EntireRow.Select
    Selection.Insert Shift:=xlDown
    Selection.RowHeight = 12.75
    ActiveCell.Offset(-1, 0).Rows("1:1").EntireRow.Select
    Selection.Copy
    ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
    Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    End Sub

    The question.......

    The macro works prefectly fine.....however, i need it, once it has copied and pasted the contents of the row above the last row down one row,,,,,,,,if this makes since.....

    to change the date field in column B (all column B) to the following month.....

    so if say the date in row 40 the last row (minus one was June 06) as asked in the macro, then once the macro copies and pastes down one the contents of the above row......change the date in row 39 (i.e. row 40 - 1) to the following month.....

    any questions you are not sure of just ask...

    thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub MyMacro()
    Dim cell As String

    cell = InputBox("Enter the end row i.e B37")
    With Range(cell)
    .EntireRow.Insert Shift:=xlDown
    .RowHeight = 12.75
    .Offset(-2, 0).EntireRow.Copy
    .Offset(-1, 0).EntireRow.PasteSpecial Paste:=xlPasteFormulas, _
    Operation:=xlNone, _
    SkipBlanks:=False, _
    Transpose:=False
    .Offset(-1, 0).Value = DateSerial( _
    Year(.Offset(-2, 0).Value), Month(.Offset(-2, 0).Value) + 1, Day(.Offset(-2, 0).Value))
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    Aug 2007
    Posts
    165
    Location
    Thanks you

    hale XLD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •