+ Reply to Thread
Results 1 to 2 of 2

Userform - copying the title from new sheet to index page

Hybrid View

Drew37 Userform - copying the title... 09-27-2010, 05:34 PM
Drew37 Re: Userform - copying the... 09-27-2010, 06:21 PM
  1. #1
    Registered User
    Join Date
    09-27-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    2

    Exclamation Userform - copying the title from new sheet to index page

    Hi,

    Very new to VBA in excel. There are two of us at work trying to sort this.

    Using excel 2007

    Short background....

    The first sheet is called 'Index'. The next sheet is called 'master'

    Using a userform it collects 3 pieces of data...a ref number, client name and address.

    The code copies the 'Master' sheet and renames it to the ref number (TF) and adds to it the client name (CN) and address (SA).

    I can do that no problem.

    
    Private Sub cmdshtadd_Click()
    
        Sheets("MASTER").Select
        Sheets("MASTER").Copy Before:=Sheets(3)
           ActiveSheet.Name = TFtxtbox
              Range("B2") = TFtxtbox
               Range("D2") = CNtxtbox
                Range("G2") = SAtxtbox
              
    End Sub

    Where TF is the ref number, CN is the client name and SA is the site address.

    The next task is to copy those 3 pieces if data that are input via the userform into the 'Index' page as well....and then for every subsequent new record/copied sheet to add its ref number(TF), name (CN) and address (SA).

    This is what we have come up with...

    
    Private Sub cmdshtadd_Click()
    Dim tfData As String
    Dim cnData As String
    Dim saData As String
    Dim IRowNum As Long
    Dim FRowNum As Long
    Dim GRowNum As Long
    
    'Sheets("INDEX").Select
    tfData = TFtxtbox.Text
    If Cells(28, 2).Value = "" Then
     IRowNum = 28
     
      Else
       IRowNum = Sheets("INDEX").UsedRange.Rows.Count + 1
       
       End If
      
     cnData = CNtxtbox.Text
     If Cells(28, 4).Value = "" Then
     FRowNum = 28
     
     Else
          FRowNum = Sheets("INDEX").UsedRange.Rows.Count + 1
      
      
      End If
      
     saData = SAtxtbox.Text
     If Cells(28, 9).Value = "" Then
     GRowNum = 28
     
     Else
          GRowNum = Sheets("INDEX").UsedRange.Rows.Count + 1
          
      End If
      
       Cells(IRowNum, 2).Value = tfData
       Cells(FRowNum, 4).Value = cnData
       Cells(GRowNum, 9).Value = saData
           
    
       Sheets("MASTER").Select
        Sheets("MASTER").Copy Before:=Sheets(3)
           ActiveSheet.Name = tfData
              Range("B2") = TFtxtbox
               Range("D2") = CNtxtbox
                Range("G2") = SAtxtbox
                
                'ActiveSheet.Move After:=ActiveSheet.Next
    
                
       TFtxtbox.Text = ""
       TFtxtbox.SetFocus
       CNtxtbox.Text = ""
       SAtxtbox.Text = ""
       'TextBox2.SetFocus
       'CommandButton1.SetFocus
       cmdshtadd.Enabled = False
              
              
    End Sub
    It sort of works but the problem is that the first record data is added to the index sheet at line 28 as the code. However the next record gets entered down at line 814 for example...if i then run the userform again it the next line of data is at 815, then 816 etc....we are lost as to why or how !!!!!

    I have attached a de-personalised version of the spreadsheet.

    Any comments appreciated.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    09-27-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Userform - copying the title from new sheet to index page

    Just a thought...does VBA look at cells which are coloured as having data in them?

    The index page has cell background color....just a thought.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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