VBA Move between sheets

MacroNobie

New Member
Joined
Mar 29, 2018
Messages
12
Hi I'm using a code to move between sheets, but when I go back and forth it does not work. Is there a way to use this code better?

Sub abcd()
Dim sht As Worksheet
Dim cell As Range
Dim actWsh As String
Application.ScreenUpdating = False

For Each sht In ThisWorkbook.Worksheets
sht.Activate
shtname = ActiveSheet.Range("B8").Value
If shtname = "FIASP + NovoRapid" Or sht.Name = "Directory" Then
shtname = ActiveSheet.Name
Worksheets(shtname).Shapes("Drp_Dwn").ControlFormat.RemoveAllItems
For Each cell In Range("TerrDrop_101")
With ActiveSheet.Shapes("Drp_Dwn").ControlFormat
.AddItem cell.Value
End With
Next
End If
Next
Sheet1.Activate
End Sub




Sub MovetoSheet()
Dim dd As DropDown


Set dd = ActiveSheet.Shapes("Drp_Dwn").OLEFormat.Object
shtnametogo = dd.List(dd.ListIndex)
'Worksheets(ActiveSheet.Name).Shapes("Drp_Dwn").Value
Worksheets(shtnametogo).Activate
Range("A1").Activate
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Not sure what you mean by "go back and forth", but you don't need to activate sheets to work with them. See if the below helps, if not please be a bit more specific in terms of the problem you're facing.

Code:
Sub abcd()
 Dim sht As Worksheet
 Dim cell As Range
 Dim actWsh As String
 Application.ScreenUpdating = False
For Each sht In ThisWorkbook.Worksheets
    With sht
        shtname = .Cells(8, 2).Value
        Select Case shtname
            Case "Directory", "FIASP + NovoRapid"
            .Shapes("Drp_Dwn").ControlFormat.RemoveAllItems
                For Each cell In .Range("TerrDrop_101")
                    .Shapes("Drp_Dwn").ControlFormat.AddItem cell.Value
                Next cell
        End Select
    End With
Next sht
     
 End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top