+ Reply to Thread
Results 1 to 3 of 3

Help Amending a bit of VBA code

Hybrid View

  1. #1
    Registered User
    Join Date
    08-05-2010
    Location
    London england
    MS-Off Ver
    Excel 2003
    Posts
    14

    Help Amending a bit of VBA code

    Hi There,

    Could somebody assit me in amending the code below. Currently the code inserts a blank row then inserts the appropriate title text.

    I would now like to make the inserted text bold and merge cells A - I in the inserted row. I just cannot get it to work

    Thanks for any help


    Sub InsertRows()
      Dim r As Long, mcol As String, i As Long
    
    
    ' find last used cell in Column E
      r = Cells(Rows.Count, "E").End(xlUp).row
    
    
     ' get value of  last used cell in column A
      mcol = Cells(r, 5).Value
    
    
     ' insert rows by looping from bottom
      For i = r To 1 Step -1
         If Cells(i, 5).Value <> mcol Then
            Rows(i + 1).Insert
            Cells(i + 1, 5).Value = PeriodTitle(mcol, i + 1)
            mcol = Cells(i, 5).Value
         End If
      Next i
    End Sub
    Function PeriodTitle(ByRef period As String, row As Long) As String
    Select Case Left(period, 2)
        Case Is = "Q1"
            PeriodTitle = "January - March " & Right(period, 4)
        Case Is = "Q2"
            PeriodTitle = "April - June " & Right(period, 4)
        Case Is = "Q3"
            PeriodTitle = "July - September " & Right(period, 4)
        Case Is = "Q4"
            CPeriodTitle = "October - December " & Right(period, 4)
        Case Else
            PeriodTitle = "Invalid Quarter in Row " & row + 1
    End Select
    End Function

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,927

    Re: Help Amending a bit of VBA code

    To Attach a Workbook:
    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    08-05-2010
    Location
    London england
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Help Amending a bit of VBA code

    sorry made an error
    Last edited by cldcp00; 02-26-2013 at 04:57 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1