+ Reply to Thread
Results 1 to 2 of 2

Still working on complex code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-28-2005
    Posts
    132

    Still working on complex code

    In the following code I have my been able to complete the following task:

    my userform will
    - add the name entered on it to the selected cells in the activate worksheet (A).
    - add the name entered into the userform to the title of a new worksheet (B) tab
    - and it will copy the contents of another worksheet to the worksheet (B)

    This is great I am so close to completing my goal.

    Now, I need to have:

    - the name of the worksheet (B) added to a cell in worksheet (B)
    - and I want to be able to have the contents of the entire row created in worksheet (A) that shares the name of worksheet (B) be copied over to certain cells in worksheet (B) as they are added to worksheet (A).

    So for example:

    If I enter John Brown into my userform it will create a row entry in worksheet (A) that says John Brown and it will create worksheet (B) that has the title John Brown and I want to have the name John Brown appear in cell A1 in worksheet (B), then I want to be able to add data to worksheet (A) and have that data fill-in and create cell info from worksheet (A) to worksheet (B) of the same name.

    current code
    Private Sub cmdAdd_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Dim newSheetName As String
    Set ws = Worksheets("Class GradeSheet")
    
    'find first empty row in database
    iRow = ws.Cells(Rows.Count, 1) _
    .End(xlUp).Offset(1, 0).Row
    
    'check for a part number
    If Trim(Me.TextBox56.Value) = "" Then
    Me.TextBox56.SetFocus
    MsgBox "Please enter last name"
    Exit Sub
    End If
    
    'copy the data to the database
    ws.Cells(iRow, 1).Value = Me.TextBox56.Value
    ws.Cells(iRow, 2).Value = Me.TextBox55.Value
    newSheetName = ws.Cells(iRow, 1) & "," & ws.Cells(iRow, 2)
    
    'clear the data
    Me.TextBox56.Value = ""
    Me.TextBox55.Value = ""
    Me.TextBox56.SetFocus
    
    For Each ws In Worksheets
    If ws.Name = newSheetName Or _
    newSheetName = "" Or _
    IsNumeric(newSheetName) Then
    MsgBox "Sheet already exists or name is invalid", vbInformation
    Exit Sub
    End If
    
    Next
    Sheets("Student Sheet").Copy before:=Sheets(1)
    Sheets(1).Name = newSheetName
    Sheets(newSheetName).Move After:=Sheets(Sheets.Count)
    
    'close userform
    Unload Me
    End Sub

  2. #2
    Registered User
    Join Date
    08-24-2005
    Posts
    33
    Which bit doesn't work? It's very complicated to follow. Maybe give an indication of what you can't get to work.

+ 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