excel vba - Can you show sheet1 when running macros on other sheets? - vba

Is there a way to run different macros on several worksheets but, always show sheet1 when the macros are running?
My sheet1 is a cover sheet (a kind of title page) with a command button. Pressing the command button runs macros on a further 5 sheets. Each sub starts by moving to the correct sheet ...
e.g.
Sheets("CDS Data").Select
... but this sheet is shown whilst the macro is running, can I stop this being shown and just show the sheet1 until all macros are finished?
Thanks

Actually ... I have found a way. By starting my macros with;
Application.ScreenUpdating = False
This seems to work.

Related

Excel full screen mode cant write to cell

I have a problem with excel in full screen mode. When I chose another sheet (via macro) and go back to previous sheet (via macro) I cant write something to cell selected cell. Any advice?
My code for fullscreen:
Private Sub Workbook_Open()
Application.DisplayFullScreen = True
Application.CommandBars("Full Screen").Visible = False
End Sub
My macro code for select sheet:
Private Sub skok()
Sheets("Sheet 2").Select
End Sub
I can testify that this problem is happening to my workbook also!
To improve visibility, I make the workbook go fullscreen with the DisplayFullscreen=True in the same sub.
Later, the user can move to Sheets 2 with macro in a command button. On sheet 2 there is a button "Save & Return" which runs a macro like
Sheets("Sheet1").select
But when we return to Sheet1 the cells seem to freeze. But the command buttons still work.The situation can be 'unlocked' when I randomly select another sheet below on the sheet tab. Then returning to Sheet1 I can then enter in the cells!
One strange thing is that although the sheet seem freeze, I can still copy & paste text in a cell using the Ctrl+C & Ctrl+V on keyboard.
I have the same problem, and it is an Excel bug! We can still copy/paste values in cells, write in cells by VBA code, but we cannot edit cells' value anymore by double-clicking the cell (or F2). The cell edition is frozen! (It is like unchecking the option "Allow editing directly in cells" (Options->Advanced options-> (Sector)"Editing options".)
To create the bug:
Click on an ActiveX control while you are in full screen mode (Application.DisplayFullScreen = True)
...and the bug is there now you cannot edit cells anymore!
The bug stays as long as the formula bar is not physically visible on your screen (fullScreen or not) and will STOP (as long as you do not recreate the bug...) as soon as the formula bar is displayed (staying in fullScreen and executing "Application.DisplayFormulaBar = True" won't work)
The bug will "temporarily" stop (with hidden formula bar) if you activate another sheet but will start again if you click on any other ActiveX control in any sheets (fullScreen or not)...
The answer is a good lesson in form. Try to avoid .Activate and .Select. If you always specify your ranges you can avoid situations like this with multiple workbooks. Use the format:
Workbooks("myBook.xlsx").Sheets("Sheet1").Range("A1").Value = "whatever"
or:
with Workbooks("myBook.xlsx").Sheets("Sheet1")
.Range("A1").Value = "A"
.Range("A2").Value = 2
.Range("A3").Value = "Blah"
End With

vba , Autofill userform from another workbook cell selection

I have a workbook that used to be one with many sheets, I have now split the sheet to different workbooks.
The problem I now have is userform population from cell selection. When all the sheets were together. This code worked great.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not (UFMJobSelectForm.ActiveControl Is Nothing) Then
Call UpdateJobSelectForm
End If
End Sub
However now the Userform is in one workbook and this code is in another. I don't want to reference library as I need it to open and close so it can be accessed for other people to use.
Thanks for any help in advance.
Edit:
What i have is 4 different workbooks with jobs on and i want to select the job and the userform populates with job details.
The code I have detects the userform is open and then calls then populates the userform using updatejobselectform. Which worked when all the sheets were in the same workbook. however no longer works now i have separated them.
When i run this code now the sheets are in there own work books i get Error: runtime erroe 424 object required.
So what i am asking is dose anyone know how i can check a userform is loaded from in a different workbook and how i can get the useform to interact with cell selection from a different workbook.
thanks again.
This looks like a code that primafacie must fire when selection change event occurs, and call a function that must update the said form.
If the code and the said form are dependent, while splitting up should they not be together.
In case there are some other constraints that do not let you do so, and are not defined in the question do feel free to update the question / comment below.
Happy to help!

Error on protected sheet

I have macro enabled workbook. Both Workbook and sheets are password protected.
Basically, I have 2 sheets. First "crater" which has a drop down list and buttons.
Second, "Uno" which has buttons again( Its a hidden sheet)
Button 1 on crater page task is to just copy the "Uno" sheet and create a new sheet. All tasks are working fine.
But my problem is, when I create a child sheet and save and close the workbook.
Next time, As soon as I open workbook I get an "error '1004'. You cannot use the command on protected sheet. You must first unprotect sheet" .
I would like to know, Where can I use the code to unprotect sheet in this case?
I am confused, please help
Use the command Worksheet("Your_Sheet_Name").Unprotect if you have a password you need to add it as well Worksheet("Your_Sheet_Name").Unprotect(Password)
You can have it in the Workbook Open and it will unlock the worksheet. However, then all the users can modify this worksheet as well.

Prevent VBA Flickering Of Charts In Excel

I have an Excel workbook that contains 2 sheets. A VBA code will load a CSV file into the 1st sheet. The VBA code will then plot data from the 1st sheet into charts in the 2nd sheet. This VBA code runs every 5 seconds and causes the charts to flicker.
Anyone has any suggestions to prevent the flickering? I have tried
Application.ScreenUpdating = False
and it does not help.
You can hide the worksheet that has the charts just before you are about to load the CSV data, and then unhide at the end of the second macro.
Have you tried running the macro outside of the VBA editor?
Even if you have set Application.ScreenUpdating = False, this will be ignored if stepping through the code or running from the editor (I believe!)

Sheet.Activate changes sheet but continues to edit data on previous sheet

I have a dialog box with a couple of buttons that launch macros to activate and change to different sheets.
The problem I am having is after I click the button, the macro activates the new sheet and I see it. But when I go to delete data, add data or try to delete a row "Nothing happens" the data on the screen is still there. If I go back to the previous sheet, the cells and rows that I had intended to delete were deleted in that sheet. It is very wierd and never seen anything like that. It appears that my macro code is note doing enough to actually change to the new sheet. I do not have this problem if I click a different sheet tab to change to it. Or if I click the dialog button to go to the new sheet and quickly do a ctrl-pgDown and Ctrl-PgUp to change from another tab and back that seems to fix the problem.
This is the code in my macro I am using to try to change to the desired tab.
Private Sub Report1Button_Click()
On Error GoTo Handler
Sheets("Report1").Activate
If StayOpenBox.Value = False Then
Unload MainMenu
End If
Exit Sub
Handler:
MsgBox "Sheet 'Report1' not found or renamed"
End Sub
Thanks for any help or suggestions
UPDATE:
Here is code that I use to call the dialog box. I have a shape on the other sheet that is assigned to this macro to open dialog box
Sub ShowMainMenu()
With UserForm1
.Show
End With
End Sub
Also there is no further code to make edits to the new sheet. My Button click simply switches to the other sheet and when I attempt to make edits manually, they are actually done on the previous sheet which is not the one I am currently looking at. So anything I do, Bold text, delete text, delete row, etc, is not done on the current sheet I am looking at, but when I return to the previous sheet the changes where made there. Im on Excel 2013, I have reproduced this problem in 2 separate files, but I will try on a different computer and older version of excel. Screenshot of my situation is below.
UPDATE 2:
I ran this xlsm file on a 2nd computer with Xls 2007 and was not having the problem. So I ran the macro on a 3rd computer that also has Excel 2013 and it is experiencing the same problem. So it is not computer specific and seems to be a problem in XLS 2013 but not in XLS 2007. I will try to find a computer with Excel 2010 to test as well, but something about this code is causing a problem in 2013 but not in older versions of excel.
When you run VBA code, it will default to using the ActiveSheet if you don't define the Sheet. When you have objects/methods that you want performed on a specific sheet, you should always specify! You can do that one of two ways:
Sheets("Report1").[Object].[Method]
'or
Sheets("Report1").[Method]
or you can pass the Sheet name to a variable and use that for shorter code
Dim Report1 As Worksheet
Set Report1 = Sheets("Report1")
Report1.[Object].[Method]
'or
Report1.[Method]
Try changing the sequence of lines in your code. I had a similar situation and it turned out that I inserted the "delete sheet" code in between the commands that were copying data from sheet1 to sheet2. When I put the deletion lines (commands) after I finished copying sheets everything started to work correctly. Many commands activate one sheet while performing and this immediately disactivates another sheet. So if you used "ActiveSheet" sommand somewhere it may be incorrectly understood - the command may be executed not on the sheet you meant.
Just use the full address for the range you are trying to manipulate, for example instead of:
Sheets("mySheet").Activate
Range("A1:B10").Cut
Sheets("myOtherSheet").Activate
Range("A1:B10").Paste
use:
Sheets("mySheet").Range("A1:A10").Cut Destination:=Sheets("myOtherSheet").Range("A1:B10")
I just had the same problem, also with Excel 2013. So even if the thread is over 9 month inactive, I want to share my solution in case somebody gets here through a Google search.
The solution was really simple. Call the userform with:
UserForm1.show vbModeless