Is there a way to enable only the worksheet scrolling while userform is active?
.show (vbmodeless)
Doesn't work for my needs as it enables all editing in worksheet, but I need to let the end user to only scroll the worksheet.
Could someone please share an answer to my question, please?
I suggest you put a vertical scroll bar on the form itself and use changes in the value of the scroll bar to scroll the worksheet using vba code. The form can then be modal and you retain control of the worksheet.
For example, I put a scrollbar on a modal form and ran this code:
Option Explicit
Private Sub ScrollBar1_Change()
Debug.Print ScrollBar1.Value
Sheet1.Rows(ScrollBar1.Value + 1).Select
End Sub
Which worked fine. You will need to adjust the settings of the scroll bar to be sensible in relation to the size of the worksheet and the way you want the user to interact, but if scrolling is the only function you want to allow, then perhaps this could work.
Related
I am newbie in excel and I really need a button that if pressed adds a certain value to the cells I selected, is that possible?
You can add buttons to Excel by enabling developer mode:
On the File tab, go to Options > Customize Ribbon.
Under Customize the Ribbon and under Main Tabs, select the Developer check box.
Then on the developer ribbon you can click insert, then select a button to draw onto the sheet.
You will then be given the option to assign a macro to the button (Also later accessible by right clicking the button).
As for the VBA code of the macro, you would need to be more specific about what functionality you require, is the 'certain value' to be added to the selected cells always the same value?
Someone answered me in two minutes on another site with this perfect code for what I wanted, thanks a lot sir. It works like magic.
Sub Add_to_Selection()
If Not IsNumeric([E4]) Then
Exit Sub
Else
Dim cell As Range
For Each cell In Selection
cell.Value = cell.Value + [E4].Value
Next cell
End If
End Sub
I am trying to disable a button on a worksheet.
I could make it invisible but I'd rather have it on screen but not clickable and greyed out so it is obviously not clickable.
Here is my script for the button:
Sub LinkFile()
Call Module1.setup
Dim btn1 As Button
Dim t As Range
Set t = Range(Cells(3, "G"), Cells(4, "I"))
Set btn1 = ACImport.Buttons.Add(Left:=t.Left, Top:=t.Top, Width:=t.Width, Height:=t.Height)
btn1.Name = "Button1"
btn1.OnAction = "FileSearch" ' MySub is executed when btn is clicked
btn1.Caption = "GO!"
End Sub
For UserForms and ActiveX buttons, this will work:
btn1.Enabled = False
For the other worksheet button, you can try:
btn1.ControlFormat.Ebabled = False
or
ACImport.Shapes("Button1").ControlFormat.Enabled = False
If those do not work then you then you will have to make a judgement call. You can switch to an ActiveX button. Remove the button from the worksheet and place it on a UserForm. Give up and let the button remain enabled. Or creatively push boundaries by employing different strategies to create the effect you want.
For example, if your set the OnAction property to vbNullString. This not only neuters the button, it also changes the button behavior during run time so that a single left click puts it into the caption editing mode. It could be used for a novel, and highly unorthodox, quasi-clipboard.
Or you could go more mainstream, perhaps with #Storax's solution.
Or maybe add some flavor to it by briefly changing the backcolor when clicked. The simple animation adds a nice touch, in fact, I prefer for that over an unclickable button.
You could jump the shark and turn all that clickyness into a mood improving anger reduction tool. Or a cruel joke on the office intern. Or a hilarious joke on your boss.
Or maybe you don't like the click so youou throw a locked transparent text box over it and tweek the sheet protections to give the user sufficient freedom while prohibiting interaction with that text box.
But in the end, if the button isn't animated then it's just as useful as a static image. So maybe you just want to use a picture instead of a button.
With so many choices, it's like the world is your oyster...
...So go find some pearls!
I'm a new VBA user. I have a workbook with multiple worksheets. Each one has it own userform for data entry. The userform shows when I click on the sheet. After I'm done entering data, the worksheet is populated and the userform closes (unload). All this works well. However, after the initial data entry is complete, the goal is to use the data on the worksheets for other applications and the userform is no longer needed. What is the code or the terminology to say the userform should not reappear again when the worksheet is clicked on? Currently, I red X out of the userform. If I click the command button to close, it repopulates and I lose all my data.
Thanks!
As A.S.H commented; you could store the information in a number of ways. An easy example is declaring a variable outside of the Macro:
Public FormOpened as boolean
And then set FormOpened as true once the form has been shown. Then you could add a check to the start of the mouse-click macro:
If FormOpened = True then Exit sub
I am designing a spreadsheet that will utilise a user form with a scroll bar on it. I need to scroll bar to update the cell specified in real time as I drag the bar using the mouse, at present it only adjusts the value In the cell when I release the mouse.
I initially wanted to use a slider but from research it appears that these can't be used in a userform.
Does anyone know any VBA code or anything that will make the scroll bar continuously update as I drag the bar using the mouse?
If you are using the scroll bar on a userform and you want the update to be while dragging you need your code to be in the scroll bar's scroll event handler. The behavior that you descried happens with the scroll bar's change event handler. To see the difference, create a new userform with a scroll bar as the only control on it. In it's code module enter the following two event-handlers. When you run it you should see B1 but not A1 updating smoothly:
Private Sub ScrollBar1_Change()
Range("A1").Value = ScrollBar1.Value
End Sub
Private Sub ScrollBar1_Scroll()
Range("B1").Value = ScrollBar1.Value
End Sub
I am maintaining a large spread sheet at work and there are ActiveX command buttons throughout the code. One sheet I am currently working on has almost 100 of these. I have made sure the button itself is visible as some of the buttons are hidden/unhidden depending on the flow of the code.
Is there a way I can find whereabouts on the sheet itself the button is located that the VBA code is pointing to? Here is a snippet:
enter code here
Private Sub CommandButton4_Click()
Application.Goto Range("Add_Trainees"), True
CommandButton3.Visible = True ' unhides menu button
CommandButton81.Visible = True ' hides SC1
CommandButton97.Visible = True ' hides SC2
End Sub
I am trying to find where on the sheet where command buttons 3, 81 and 97 are located.
TIA for any help/suggestions.
I think pnuts provides the correct way to find out where the buttons are.
I would also suggest to open the panel from "Developer" -> "Properties". In that panel, you can check out all the ActiveX Controls, including the command buttons, in the list.