+ Reply to Thread
Results 1 to 2 of 2

Combine VBA into a single one

Hybrid View

JJ77 Combine VBA into a single one 09-07-2016, 02:08 PM
davesexcel Re: Combine VBA into a single... 09-07-2016, 02:11 PM
  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    27

    Question Combine VBA into a single one

    Hi.
    I have some VBA's codes, some I found online that works for what I need.
    I have 3 separate ones that I run, but I would like to have it all as ONE.
    I copied all together, but it gets messy and it does not do what each one does separately.
    How do I do that?


    CODE 1

    Sub CopyFromWorksheets()
    Dim wrk As Workbook
    Dim sht As Worksheet
    Dim trg As Worksheet
    Dim rng As Range
    Dim colCount As Integer
    Set wrk = ActiveWorkbook
    For Each sht In wrk.Worksheets

    If sht.Name = "Master" Then
    MsgBox "There is a worksheet called as 'Master'." & vbCrLf & _
    "Please remove or rename this worksheet since 'Master' would be" & _
    "the name of the result worksheet of this process.", vbOKOnly + vbExclamation, "Error"
    Exit Sub
    End If
    Next sht

    Application.ScreenUpdating = False

    Set trg = wrk.Worksheets.Add(After:=wrk.Worksheets(wrk.Worksheets.Count))

    trg.Name = "Master"

    Set sht = wrk.Worksheets(1)
    colCount = sht.Cells(1, 255).End(xlToLeft).Column

    With trg.Cells(1, 1).Resize(1, colCount)
    .Value = sht.Cells(1, 1).Resize(1, colCount).Value

    .Font.Bold = True
    End With

    For Each sht In wrk.Worksheets

    If sht.Index = wrk.Worksheets.Count Then
    Exit For
    End If

    Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End(xlUp).Resize(, colCount))

    trg.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value
    Next sht

    trg.Columns.AutoFit

    Application.ScreenUpdating = True
    End Sub


    CODE 2

    Sub sbVBS_To_Delete_Specific_Columns()
    Sheets("Master").Range("A:A,B:B,C:C,N:O,R:R,T:Y,AB:AD,AG:AG,AQ:AU").EntireColumn.Delete
    End Sub

    CODE 3

    Sub Format_Master()
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Columns("L:L").Select
    Selection.Cut Destination:=Columns("B:B")
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "SDt"
    Columns("L:L").Select
    Selection.Delete Shift:=xlToLeft
    End Sub



    Thanks
    Jake

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Combine VBA into a single one

    At the end of your first macro code, call the next macro

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Combine values from two or more into a single row.
    By Kimston in forum Excel General
    Replies: 18
    Last Post: 03-01-2015, 07:21 PM
  2. Combine MANY tabs (with single column) into SINGLE tab.
    By nick1000 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-17-2013, 02:31 PM
  3. Replies: 6
    Last Post: 08-31-2011, 10:00 AM
  4. Combine These Functions to a Single Cell
    By BigMike66 in forum Excel General
    Replies: 2
    Last Post: 10-21-2009, 02:13 AM
  5. [SOLVED] combine the two into a single formula please
    By Steved in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-07-2005, 09:05 PM
  6. [SOLVED] how to combine several columns into a single column
    By jims in forum Excel General
    Replies: 9
    Last Post: 08-15-2005, 07:05 AM
  7. combine different worksheets to a single worksheet
    By Norman Kong via OfficeKB.com in forum Excel General
    Replies: 4
    Last Post: 04-19-2005, 08:06 AM

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