Consulting

Results 1 to 8 of 8

Thread: Run VBA Code of diffrent sheet Automaticly

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    Question Run VBA Code of diffrent sheet Automaticly

    I have 6 sheet . and also 6 VBA Code .

    is there any code that cab be run for example : (Automaticly)that mean when the First VBA code will be done second VBA code will be start on second sheet .... .


    Sheet A First VBA Code
    Sheet B Second VBA Code
    Sheet C Third VBA Code
    Sheet D Fourth VBA Code
    Sheet E Fifth VBA Code
    Sheet F Sixth VBA Code


    .....

    if is it possible please help me .

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yes, simple call all 6 procedures from another procedure.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Could you please help me how can i do this ? have 6 diffrent sheet with 6 diffrent VBA code and want start from sheet A with VBA code 1 after that run VBA code 2 for sheet B and ... and it will be automaticly .

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I cannot say it any differently than I already have. What does this code looke like?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    my active sheet is A and i want when i run VBA and when it will be done go to another sheet and run another VBA code automaticlyand again for anoter sheet . that mean i just run 1 Micro and after taht will be automaticly .

    hope you understand me .

    Thank you .

  6. #6
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    That mean when the first vba done in sheet A i use Worksheets("B").Activate that mean show sheet b and also i have a vba for this sheet and i want to start automaticly . hope you understand me .
    Last edited by parscon; 02-24-2012 at 05:01 PM.

  7. #7
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Also i need this VBA code to be run on sheet B- Sheet c-Sheet D- Sheet E- Sheet F .

    [vba]
    Sub TEST()
    Dim x As Long
    Dim LastRow As Long
    LastRow = Range("B65536").End(xlUp).Row
    For x = LastRow To 1 Step -1
    If Application.WorksheetFunction.CountIf(Range("B1:B" & x), Range("B" & x).Text) > 1 Then
    Range("B" & x).Delete Shift:=xlUp
    End If
    Next x
    On Error Resume Next
    Range(Cells(1, "B"), Cells(LastRow, "B")).SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
    On Error GoTo 0


    Dim a As Range

    With ActiveSheet

    For Each a In ActiveSheet.UsedRange
    a = Replace(a, " (", "(")
    a = Replace(a, "(BLM)", ", ")
    a = Replace(a, "POE", "")
    a = Replace(a, "POE ", "")
    a = Replace(a, "(POE LM)", "(LM), ")
    a = Replace(a, "kerman)", "kerman), ")
    a = Replace(a, "PCMN", "PCMS, ")
    Next

    Cells.Select
    Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal


    With Sheets("sheetFinal")
    .Range(.Range("B1"), .Range("B65536").End(xlUp)).Copy
    End With
    Sheets("SRP-Final").[B65536].End(xlUp)(1).PasteSpecial Paste:=xlValues


    Cells.Select
    Selection.ClearContents
    Range("A1").Select
    End With
    End Sub
    [/vba]
    Last edited by Aussiebear; 02-25-2012 at 02:09 PM. Reason: adjusted the code tags for the correct usage

  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Untested, but you want something like this. Also, for your initial query, use sheet references properly and avoid working with ActiveSheet

    [vba]Sub TEST()
    Dim x As Long
    Dim LastRow As Long

    Dim arr(), sh

    arr = Array("sheet B", "Sheet c", "Sheet D", "Sheet E", "Sheet F")

    For Each sh In arr
    Set ws = Sheets(sh)
    With ws

    LastRow = .Range("B65536").End(xlUp).Row
    For x = LastRow To 1 Step -1
    If Application.WorksheetFunction.CountIf(.Range("B1:B" & x), .Range("B" & x).Text) > 1 Then
    .Range("B" & x).Delete Shift:=xlUp
    End If
    Next x
    On Error Resume Next
    Range(.Cells(1, "B"), .Cells(LastRow, "B")).SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
    On Error GoTo 0


    Dim a As Range


    For Each a In .UsedRange
    a = Replace(a, " (", "(")
    a = Replace(a, "(BLM)", ", ")
    a = Replace(a, "POE", "")
    a = Replace(a, "POE ", "")
    a = Replace(a, "(POE LM)", "(LM), ")
    a = Replace(a, "kerman)", "kerman), ")
    a = Replace(a, "PCMN", "PCMS, ")
    Next

    .Cells.Sort Key1:=.Range("B1"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal


    With Sheets("sheetFinal")
    .Range(.Range("B1"), .Range("B65536").End(xlUp)).Copy
    End With
    Sheets("SRP-Final").[B65536].End(xlUp)(1).PasteSpecial Paste:=xlValues


    .Cells.ClearContents
    End With
    End Sub[/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •