+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    03-19-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    3

    Creating an index using macros

    This is probably an extremely basic question!!

    I am new to macros (obviously) and i am trying to create a workbook that has an index
    and identical 'forms' on different sheets. I am trying to record a macro so every time i
    press a button the index sheet automatically adds a row and new form reference number, aswell as copying my first form to a new sheet and updating the reference number on that form with reference to the index!!

    My problem is getting the the index sheet to add rows that go from 001 to 002 to 003 etc. on the same button.

    Please Help!!!

    Thanks,

    Damien
    Last edited by damocull; 03-20-2010 at 05:28 AM.

  2. #2
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Basic Macro problem

    Welcome to the forum, damocull.

    Please take a few minutes to read the forum rules, and then amend your thread title accordingly.

    Thanks.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Basic Macro problem

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  4. #4
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Creating an index using macros

    damocull, you haven't provided enough information for anyone to help.

    Post a workbook and explain exactly what you want to happen.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    03-19-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    3

    Red face Re: Creating an index using macros

    Hi, sorry for being so unhelpful. I have attached the workbook.

    I think I need to create a loop, the macro I have now is on the right track.

    I need the button to:
    make columns A, D & E increase sequentially by a value of 1 & create a new worksheet everytime its pressed

    Columns B5 & C5 will be entered manually but still linked to the new worksheets.

    It would be handy if the name of the new worksheet name increased by a value of 1 everytime a new one was created.

    Thanks,

    Damien
    Attached Files Attached Files

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,496

    Re: Creating an index using macros

    Hello damocull,

    I have added the macro below to the attached workbook. This macro is now attached to the button on the "index" worksheet.
    Code:
    Sub IncrementValues()
    
      Dim Rng As Range
      Dim RngEnd As Range
      Dim ShtName As String
      Dim Wks As Worksheet
      
        Set Wks = ActiveSheet
        
        Set Rng = Wks.Range("A2:E5")
        Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
        
        If RngEnd.Row < Rng.Row Then Exit Sub
        
        Set Rng = RngEnd.Offset(1, 0)
        
          With Rng
           .Item(1, 1) = .Item(0, 1) + 1
           .Item(1, 4) = .Item(0, 4) + 1
           .Item(1, 5) = .Item(0, 5) + 1
          End With
          
          ShtName = Rng.Item(1, 1)
          
          On Error Resume Next
            Set Wks = Worksheets(ShtName)
            If Err = 9 Then
              Err.Clear
              Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = ShtName
              Worksheets("Index").Activate
            End If
          On Error GoTo 0
          
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Registered User
    Join Date
    03-19-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Creating an index using macros

    Leith Ross you are a legend, thanks a million,

    Damien,

    Go n-éirí an bóthar leat!!

  8. #8
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Creating an index using macros

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

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.2.0