I've created a macros-enabled Excel file where, when clicking into a specific cell, a pop-up calendar appears. It is an ActiveX control (Microsoft Date and Time Picker Control 6.0 (SP4)). From time to time the calendar control appears next to the clicked cell and is unclickable and a duplicate control appears in the left top corner of the worksheet and this one is clickable.
I would like it to appear just next to the clicked cell. What could be wrong?
Sub Worksheet_SelectionChange(ByVal Target As Range)
With Sheet1.startPicker
If Not Intersect(Target, Range("E2:E10000")) Is Nothing Then
.Visible = True
.Top = Target.Top
.Right = Target.Offset(0, 1).Right
Else
.Visible = False
End If
End With
End Sub
Private Sub startPicker_Change()
ActiveCell.Value = Me.startPicker.Value
End Sub
When I click on the date picker control in Design Mode, then the name is set to startpicker and in the formula bar it says "=EMBED("MSComCtl2.DTPicker.1";"")"
Just now I tried changing the Checkbox (in the Calendar Properties) to True. Then when I went back, the duplicate one was gone. Changed it back to False and it didn't return.
Related
I've created an ActiveX dropdown list and each option is linked to a bookmark for the text. Under the ActiveX controls there are the bookmarks (R1 andR2), hidden.
When I hit the btnselect button, all the other bookmarks, except the selected one, get deleted and the selected one becomes visible.
In the bookmark R2
I have a MacroButton for showing/hiding another text (CollapseMentiuniReclamant). When clicking the button it runs either Expand1 sub or Collapse1 sub, but the bookmark CollapseMentiuniReclamant doesn't show up.
I've simplified the document and codes as much as possible. Link to the document - https://wetransfer.com/downloads/1caea3c5d3b05e226e8b8f6a29760ad220190522071742/15db59.
The vba code is:
Private Sub btnselect_Click()
If ComboBox1.Value = "1" Then
Bookmarks("R1").Range.Font.Hidden = False
Bookmarks("R2").Range.Font.Hidden = False
Bookmarks("R2").Range.Delete
End If
If ComboBox1.Value = "2" Then
Bookmarks("R1").Range.Font.Hidden = False
Bookmarks("R1").Range.Delete
Bookmarks("R2").Range.Font.Hidden = False
Bookmarks("CollapseMentiuniReclamant").Range.Font.Hidden = True
End If
End Sub
Sub Expand1()
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Collapse1").Insert _
Where:=Selection.Range
Bookmarks("CollapseMentiuniReclamant").Range.Font.Hidden = False
End Sub
Sub Collapse1()
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Expand1").Insert _
Where:=Selection.Range
Bookmarks("CollapseMentiuniReclamant").Range.Font.Hidden = True
End Sub
Update: I've simplified the last part of code and the problem still persists:
Sub Expand1()
Bookmarks("CollapseMentiuniReclamant").Range.Font.Hidden = False
End Sub
I've even removed the button entirely and ran the macro from View Macros Tab and it's not working.
Why doesn't CollapseMentiuniReclamant show up?
It's not showing up because what you're trying to hide/unhide isn't inside the bookmarked range. In any event, you should be inserting/deleting the content, not simply toggling it's hidden property. Making something hidden is no guarantee it won't be seen or printed (even if not seen), as those settings depend on how the end user has Word configured.
I have three rows.I want to hide the data in those rows and display those rows in different color.I tried searching but only found Entirerow.hidden,which hides the row number as well. Is it possible to only hide the data in the rows and display it using some other color?
The below code will change the background color to Yellow for rows 1 to 3.
Sub ChangeBackColorForSpecificRows()
Rows("1:3").Interior.Color = 65535
End Sub
Change the Rows and Interior Color to suit your requirement.
Edit:-
formupahidden set to true not working neither formatting it to locked
and hidden ,is hiding the content of formula bar – Sunaina
Copy the below code and do right click on sheet tab and select view code and paste it.
Close the VBA window (Alt+Q to close VBA window) and return to that sheet and check.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Rows("1:3")) Is Nothing Then
If Application.DisplayFormulaBar Then Application.DisplayFormulaBar = False
Else
If Not Application.DisplayFormulaBar Then Application.DisplayFormulaBar = True
End If
End Sub
Following this video I have a spreadsheet that has a "Edit History" box on it that scrolls up and down. It uses a forms control scroll box and a list on a secondary sheet to create a scrollable list. The problem with this is that you cannot then edit the information in the scroll box (you must edit it on the secondary sheet).
I have VBA that automatically enters the person's name into the scrollbox when they edit any part of the sheet, and then enters "Note:" below that. I want the person to be able to edit the "Note:" box so that they can enter the reason they are editing the sheet:
John Smith and James Appleseed are previous users of this sheet. When Wayne Smith comes in to edit the sheet, as soon as he makes a change, it adds "Wayne Smith" and "Note:" to the sheet. (I already have this part working using VBA).
Because of the way that the scroll able list is implemented, it is actually all just formulas within this edit history box. If I double click "Note:" to try and edit it, this is what appears:
But what I want to happen is the ability to edit the "Note:" box (without having to switch to the secondary sheet where the list is actually stored). Essentially I want to make a scroll able text box that is also directly editable, and works with VBA.
Is there any way to do this?
I put together a working example of how to do this.
You can download the workbook here.
This method uses two sheets in a workbook... Sheet1 for the listbox and listboxdata for the data. Sheet1 can be called anything you like.
It would probably be wise to hide the listboxdata sheet.
On Sheet1 you need a Forms Control scrollbar. Use the Name Box to rename it: ScrollBar1. Assign to it the Scroll() procedure.
All of the code for this app should be placed in the Sheet1 code module:
Option Explicit
Private Const LISTBOX_SCROLLBAR = "scrollbar1"
Private Const LISTBOX_DATASHEET = "listboxdata"
Private Const LISTBOX_DATAHEADR = "a1"
Private Const LISTBOX_SCROLLMAX = 50
Private Const LISTBOX_SCROLLMIN = 1
Private Sub Scroll()
Dim ListBoxRows&, n&, ndx&, v
On Error Resume Next
With Shapes(LISTBOX_SCROLLBAR)
SetProps ndx
ListBoxRows = .BottomRightCell.Row - .TopLeftCell.Row
v = ThisWorkbook.Sheets(LISTBOX_DATASHEET).Range(LISTBOX_DATAHEADR).Resize(ListBoxRows).Offset(ndx)
Application.EnableEvents = False
.TopLeftCell(, 0).Resize(ListBoxRows) = v
End With
Application.EnableEvents = True
End Sub
Private Sub Update(Target As Range)
With Shapes(LISTBOX_SCROLLBAR)
If Target.Column = .TopLeftCell(, 0).Column Then
If Target.Row >= .TopLeftCell.Row And Target.Row <= .BottomRightCell.Row Then
If Target.Count = 1 Then
ThisWorkbook.Sheets(LISTBOX_DATASHEET).Range(LISTBOX_DATAHEADR).Offset(.ControlFormat.Value + Target.Row - .TopLeftCell.Row) = Target
Else
Scroll
End If
End If
End If
End With
End Sub
Private Sub SetProps(Optional ndx&)
With Shapes(LISTBOX_SCROLLBAR).ControlFormat
.Min = LISTBOX_SCROLLMIN
.Max = LISTBOX_SCROLLMAX
ndx = .Value
End With
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Update Target
End Sub
Private Sub Worksheet_Activate()
SetProps
End Sub
That's it.
No formulas required in the listbox and any changes made to the cells in the listbox will be written to the source data and kept.
So pretty much what I am trying to do is create a floating text box that would be on the right of the spreadsheet. When a user selects a row/cell it will then place a comment or message with details about that cell in there rather than a small little comment box.
I have tried to use the UserForm Box but its not really what I'm looking for.
Example:
User Selects Cell A4, I would like a message to read in a floating text when that cell is selected. Then if a user selects Cell B6 a different message appears in that box.
Does that makes sense?
Update:
The Following Code Shows a UserForm box when a certain cell is selected:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Definition As String
If Intersect(Target, Range("C6:D6")) Is Nothing Then Exit Sub
Select Case Target.Row
Case 22
Definition = "Text Here"
Case 23
Definition = "Text Here Again"
End Select
UserForm1.Label1.Caption = Definition
UserForm1.Show
End Sub
I don't want to use a UserForm box as its not stationary on the Worksheet itself. I want it so a Text Box that always appears on the right hand side of the worksheet to display a set message or context when the cell is selected. It will be different then what is stored in the actual cell.
Use a Data Validation message. This type of message "pops-up" whenever you click on a cell:
You can place a Label or TextBox control directly in the worksheet - make sure it's an ActiveX control, not a Forms control - and position it dynamically using the worksheet's SelectionChange event:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Me.lblText
.Visible = False
Select Case Target.Row
Case 22
.Caption = "Text Here Again"
Case 23
.Caption = "Text Here Again"
Case Else
.Visible = False
Exit Sub
End Select
' Place the label to the right of the target cell
.Left = Target.Left + Target.Width
' Or place the label in the far left of the window
'.Left; =; Application.ActiveWindow.VisibleRange.Width; -; .Width
.Top = Target.Top - 0.75 ' cell borders
.Visible = True
End With
End Sub
Some hints:
Make sure the 'Placement' property of a label is 2
(XlPlacement.xlMove), as other values give you Free-Floating or
Move-and-Size.
I strongly advise you to set the background colour of the control to
&H80000004&, the predefined Windows scheme colour for menu and form
backgrounds; likewise, the foreground to &H80000008&, the menu text
colour. This ensures visibility for users who have their own colour
settings, and explicitly supports users who specify an accessible or
assistive colour scheme to ameliorate a visual impairment.
My code relies on your sheet supporting event procedures in VBA, and
on ActiveX controls. It won't work in .xlsx sheets, and it may be
blocked (or accompanied by warning dialogues) if your operating
environment has a heavy-handed security policy.
Copy-and-paste might be affected by my use of the Worksheet
SelectionChange event.
Right-Click the control in design view for the 'Format Control' menu
and uncheck 'Print Control' - if the users print the sheet, they'll
want to see the cell contents, not the label.
Also: the label's in the way of selecting and editing the control
it's sitting over. Maybe you want it 4-5mm to the right, so the users
can get the mouse into that cell. Alternately, do this in the label's
Click() or MouseMove event:
Me.lblText.Visible = False
You might draw an obvious conclusion from all this: the native comment or data validation label is a better bet than using forms and ActiveX controls.
I'm trying to put a combobox inside active worksheet (but not activeX combobox), choose a list to fill and linked cell. It is an easy task, for example:
Sub make_combobox()
ActiveSheet.DropDowns.Add(69.75, 1.5, 79.5, 40.5).Select
Selection.Name = "combo"
ActiveSheet.Shapes("combo").Select
With Selection
.ListFillRange = "$A$1:$A$3"
.LinkedCell = "$D$1"
.DropDownLines = 8
.Display3DShading = False
End With
End Sub
I tried to put macro in worksheet containing this combobox, which will show msgbox whenever chosen linked cell is changed according to the chosen option in combobox. I wrote this in Worksheet section:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D1")) Is Nothing Then
MsgBox "It works!"
End If
End Sub
Unfortunately, it doesn't work (Actually, it works when I change a value in D1 manually, but not work as a result of change in combobox).
Just assign a macro to the control using the OnAction property. It will run after every change made to the Combobox's value.