Results 1 to 7 of 7

Combining snippets of VBA to create new sheet and add formatted cells to another page.

Threaded View

  1. #1
    Forum Contributor
    Join Date
    08-14-2014
    Location
    US
    MS-Off Ver
    2013
    Posts
    135

    Combining snippets of VBA to create new sheet and add formatted cells to another page.

    Not honestly certain I will be able to explain this very well but I try. I managed to create my very own code to Create a new sheet, and name the sheet from a userform. Now as far as that part goes I do not need any assistance as of yet. However, I am trying to have 4 items from the userform added to another sheet ("Welcome"). My problem is I cant seem to find the last row and skip a row to input the data and formatting. Not sure what to give here so I will give the three snippets. One is from a recorded macro for the formatting I tried to edit.

    This first one is what I think or thought I had to add in order to get the values from the textbox's to show in the welcome sheet

       With Worksheets("Welcome")
          .Cells(emptyRow, 1).Value = txtTerm.Value
          .Cells(emptyRow, 2).Value = "Course Names:"
          .Cells(emptyRow, 3).Value = txtCourse1.Value
          .Cells(emptyRow, 4).Value = txtCourse2.Value
          .Cells(emptyRow, 5).Value = txtCourse3.Value
       End With

    Here is the recorded macro that I may or not have messed up trying to edit it.

        Sheets("Welcome").Select
        Range("A" & Rows.Count).End(xlUp).Offset(2).Select
        Dim xlEdgeType As Variant
        
        '******* This is a single cell which Should also have Term Name *********
        For Each xlEdgeType In Array(xlEdgeLeft, xlEdgeTop, xlEdgeRight, _
                xlEdgeBottom, xlInsideVertical, xlInsideHorizontal)
            With ActiveSheet.Range("A26").Borders(xlEdgeType)
                .LineStyle = xlContinuous
                .ThemeColor = 2
                .TintAndShade = 0
                .Weight = xlThin
            End With
        '******* This is for the above single cell to color it green *********
            With Selection.Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .ThemeColor = xlThemeColorAccent6
                .TintAndShade = 0.799981688894314
                .PatternTintAndShade = 0
            End With
        Next xlEdgeType
        '******* This is for 4 rows 8 Columns with borders around them *********
        For Each xlEdgeType In Array(xlEdgeLeft, xlEdgeTop, xlEdgeRight, _
                xlEdgeBottom, xlInsideVertical, xlInsideHorizontal)
            With ActiveSheet.Range("A:H").Borders(xlEdgeType)
                .LineStyle = xlContinuous
                .ThemeColor = 2
                .TintAndShade = 0
                .Weight = xlThin
            End With
        Next xlEdgeType
    I need both of snippets somehow combined with this part which is for the form that creates the new worksheet.

    Private Sub shtCreate_Click()
     
     Sheets("MasterSheet").Visible = True
     Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = txtTerm.Value
      
     If SelCourse1.Value = "Weighted" Then
     Sheets("MasterSheet").Columns("G:L").Copy Destination:=Sheets(txtTerm.Value).Range("A1")
     Range("A1").Value = txtCourse1.Text
     Else:
     Sheets("MasterSheet").Columns("A:F").Copy Destination:=Sheets(txtTerm.Value).Range("A1")
     Range("A1").Value = txtCourse1.Text
     End If
     
     If SelCourse2.Value = "Weighted" Then
     Sheets("MasterSheet").Columns("S:X").Copy Destination:=Sheets(txtTerm.Value).Range("G1")
     Range("G1").Value = txtCourse2.Text
     Else:
     Sheets("MasterSheet").Columns("M:R").Copy Destination:=Sheets(txtTerm.Value).Range("G1")
     Range("G1").Value = txtCourse2.Text
     End If
     
     If SelCourse3.Value = "Weighted" Then
     Sheets("MasterSheet").Columns("AE:AJ").Copy Destination:=Sheets(txtTerm.Value).Range("M1")
     Range("M1").Value = txtCourse3.Text
     Else:
     Sheets("MasterSheet").Columns("Y:AD").Copy Destination:=Sheets(txtTerm.Value).Range("M1")
     Range("M1").Value = txtCourse3.Text
     End If
    
     Sheets("MasterSheet").Visible = False
        Unload Me
    End Sub
    Hopefully this all made sense and someone can lend me hand here is the workbook
    https://www.dropbox.com/s/rgliaz7ef1...cept.xlsm?dl=0


    Modified the last piece of code to a more efficient version it copies the corresponding columns and pastes them instead of copying the page and hide the columns I don't need.
    Last edited by Mr_Bill; 09-13-2014 at 12:11 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Combining cells loses digits in formatted cells
    By marielouise1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-03-2013, 10:11 AM
  2. Replies: 3
    Last Post: 12-31-2012, 12:03 PM
  3. [SOLVED] Selectively referencing formatted text (bold cells) from one sheet to another
    By Stndsh in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-18-2011, 11:05 PM
  4. [SOLVED] i formatted an excel sheet, to fit my page, how do i add a page?
    By newnewnew in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 08-08-2006, 10:30 PM
  5. [SOLVED] Converting 'General' formatted cells to Text formatted cell using.
    By Zahid Khan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-12-2005, 04:06 PM

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