• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VB Code to press several buttons in different worksheet

Ateeb Ali

Member
I have a worksheet and it has several button in each sheet, I wanted to assign following macro and need help in coding.

There is a button in sheet "Summary", Button Name "New"
When I press it, following should happen.
Click Top Left "Back" button on Sheet "Summary"
Click Top Left "Back" button on Sheet "Report"

Now we are at Sheet: Layout
Press Button "Clear All"
Click Top Left "Back" button

Now we are at Sheet: Machines Data
Clear contents range C11:C17
Click Top Left "Back" button

Now we are at Sheet: Operations
Press Button "DeSelect All"
Click "Back" button

Now we are at Sheet: Picture
Clear Picture Cell : B4:D20
Click Top Left "Back" button

Now we are at Sheet: Garment Detail
Clear contents range C32:D32
Clear contents range F6:G7
Clear contents range F12:G13
Click Top Left "Back" button

Now we are at Sheet: New Style
Clear contents range J9:L10
Clear contents range F14:H15
Clear contents range F18:H19
Clear contents range J13:L14
Click Top Left "Back" button
We should be now at Welcome Sheet Range A1

End
 

Attachments

  • New.xlsb
    1,000.5 KB · Views: 3
This code I have designed but not working

Code:
Sub Macro1()
'
' Macro1 Macro
'

'
ActiveSheet.Layout.Select
'Modified 12/29/2018 2:34:32 AM  EST
Application.ScreenUpdating = False
Dim i As Long
For i = 6 To 250 Step 4
Cells(i, 2).Resize(, 16).ClearContents
Next
Range("B9:B250").Select
Range("B250").Activate
Selection.EntireRow.Hidden = True
Range("B6").Select

Application.ScreenUpdating = True
  
  
  
  
    ActiveSheet.Machines Data.Select
    Range("C11:C27").Select
    Selection.ClearContents
    Range("B10").Select
  
    ActiveSheet.Operations.Select
    'Updateby Extendoffice 20161129
    Dim chkBox As Excel.CheckBox
    Application.ScreenUpdating = False
    For Each chkBox In ActiveSheet.CheckBoxes
            chkBox.Value = xlOff
    Next chkBox
    Application.ScreenUpdating = True
  
    ActiveSheet.Picture.Select
    For Each Pic In ActiveSheet.Pictures
        If Not Intersect(Pic.TopLeftCell, Range("B4:D20")) Is Nothing Then
            Pic.Delete
        End If
    Next Pic
          
    ActiveSheet.Garment Detail.Select
    Range("C5:D32").Select
    Selection.ClearContents
    Range("F12:G13").Select
    Selection.ClearContents
    Range("I6:J7").Select
    Selection.ClearContents
    Range("F6:G7").Select
    Selection.ClearContents
    ActiveWindow.SmallScroll Down:=0
    Range("D9").Select
    ActiveSheet.New Style.Select
    Range("J9:L10").Select
    Selection.ClearContents
    Range("J13:L14").Select
    Selection.ClearContents
    Range("F14:H15").Select
    Selection.ClearContents
    ActiveWindow.SmallScroll Down:=3
    Range("F18:H19").Select
    Selection.ClearContents
    Range("K17").Select
    ActiveWindow.SmallScroll Down:=-6
    ActiveSheet.Welcome.Select
End Sub
 
Last edited by a moderator:
Finally this code worked

Code:
Sub New_TCS()
Range("O6").Value = Range("O6").Value + 1

For sh = 1 To Sheets.Count
        Sheets(sh).Visible = -1
    Next sh


'
' Macro1 Macro
'

'
ActiveSheet.Previous.Select
ActiveSheet.Previous.Select
'Modified 12/29/2018 2:34:32 AM  EST
Application.ScreenUpdating = False
Dim i As Long
For i = 6 To 250 Step 4
Cells(i, 2).Resize(, 16).ClearContents
Next
Range("B9:B250").Select
Range("B250").Activate
Selection.EntireRow.Hidden = True
Range("B6").Select

Application.ScreenUpdating = True
  
  
  
  
ActiveSheet.Previous.Select
    Range("C11:C27").Select
    Selection.ClearContents
    Range("B10").Select
  
    ActiveSheet.Previous.Select
    'Updateby Extendoffice 20161129
    Dim chkBox As Excel.CheckBox
    Application.ScreenUpdating = False
    For Each chkBox In ActiveSheet.CheckBoxes
            chkBox.Value = xlOff
    Next chkBox
    Application.ScreenUpdating = True
  
    ActiveSheet.Previous.Select
    For Each Pic In ActiveSheet.Pictures
        If Not Intersect(Pic.TopLeftCell, Range("B4:D20")) Is Nothing Then
            Pic.Delete
        End If
    Next Pic
          
    ActiveSheet.Previous.Select
    Range("C5:D32").Select
    Selection.ClearContents
    Range("F12:G13").Select
    Selection.ClearContents
    Range("I6:J7").Select
    Selection.ClearContents
    Range("F6:G7").Select
    Selection.ClearContents
    ActiveWindow.SmallScroll Down:=0
    Range("D9").Select
  
    ActiveSheet.Previous.Select
    Range("J9:L10").Select
    Selection.ClearContents
    Range("J13:L14").Select
    Selection.ClearContents
    Range("F14:H15").Select
    Selection.ClearContents
    ActiveWindow.SmallScroll Down:=3
    Range("F18:H19").Select
    Selection.ClearContents
    Range("K17").Select
    ActiveWindow.SmallScroll Down:=-6
  
    ActiveSheet.Previous.Select
    '
    Sheets(Array("New Style", "Garment Detail", "Picture", "Operations", _
        "Machines Data", "Layout", "Report", "Summary", "Short")).Select
    Sheets("Short").Activate
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Consolidated Report").Select
    ActiveWindow.SelectedSheets.Visible = False
    Range("F8").Select

End Sub
 
Last edited by a moderator:
Back
Top