Trying to get this small vba code to work the right way, but cant figure it out

zone709

Well-known Member
Joined
Mar 1, 2016
Messages
2,125
Office Version
  1. 365
Platform
  1. Windows
As you may see its probably not the best way efficient, but it works almost the way I want it to except. At the end of macro I need it to leave me on workbook

Workbooks("FIle Zed Upload For Time Macro 2.xlsm").Activate

Which for some reason it doesn't now. If I play it slow motion then it does. So I'm confused on where the issue is.
Code:
Sub MoveCopy()
    Sheets("Name Correction").Copy Before:=Workbooks( _
    "FIle Zed Upload For Time Macro 2.xlsm").Sheets(1)
    Windows("FIle Zed Upload For Time Macro 2.xlsm").Activate
    Sheets("Name Correction").Move After:=Sheets(4)
    Workbooks("FIle Zed Upload For Time Macro 2.xlsm").Activate
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Do you have more than one workbook open? If so, which workbook is the macro in?
 
Upvote 0
Yes I do I have 2 workbooks open. The one holding the macro in module is this FIle Zed Upload For Time Macro 2.xlsm and I need both to stay open at this point of time but the File Zed to be selected. Not the other one
 
Last edited:
Upvote 0
Code:
Sub MoveCopy()
    Sheets("Name Correction").Copy Before:=Workbooks( _
    "FIle Zed Upload For Time Macro 2.xlsm").Sheets(1)
    Windows("FIle Zed Upload For Time Macro 2.xlsm").Activate
    Sheets("Name Correction").Move After:=Sheets(4)
   ' Workbooks("FIle Zed Upload For Time Macro 2.xlsm").Activate
   [COLOR=#FFA07A]ThisWorkbook.Sheets(1).Select[/COLOR]
End Sub
 
Last edited:
Upvote 0
Hi it still leaves me on first workbook I don't know why. The first workbook is named "Time" with sheets named -- Sheets("Name Correction"). and the only thing I do is copy that sheet to the book called -->FIle Zed Upload For Time Macro 2.xlsm

Move the tab down to 4 and stay on that sheet. weird
 
Upvote 0
Do you have any sheet or workbook events?
 
Upvote 0
Wait yes maybe this is causing it.

Before I run code above I use this before it, but I didn't post it cause I don't have an issue with it. It opens the workbook time for me. The sheet in this workbook I copy to other. Can this below be causing the problem?

Code:
Sub Set_Open_ExistingWorkbook()
Dim wkb As Workbook
Set wkb = Workbooks.Open("C:\Users\Frank\Desktop\Time")
End Sub
 
Upvote 0
That is not an event & shouldn't be a problem
Events are in the sheet or thisworkbook modules & will start something like
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
or
Private Sub Worksheet_Activate()
or
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
 
Upvote 0
yeah I get you. I realize it now I use this for another sheet I have when it opens it saves automatically. This problem I'm having with this. I can figure it out why it wont select the sheet I need it to go to at the end. If I play it in slow motion then it will do what I need. Again this macro is the last I'm running and nothing after that is causing this problem. I tried even .select and used range.B4 example to get me back to the sheet I need but nothing.
 
Upvote 0
Hi I just wanted you guys to know. What I'm going to do for now is close the book "Time" VBA. Then it will leave me on the sheet I need to be on. Then open it back up when needed in the code. I been trying to figure out all day why I cant just leave both open and select the one I need, but its something I'm still going to try and figure out. Cheers
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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