Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-19-2025, 11:26 AM
roger.stern@mail.com roger.stern@mail.com is offline Getting VBA Macro to work with a range of cells Windows 10 Getting VBA Macro to work with a range of cells Office 2021
Novice
Getting VBA Macro to work with a range of cells
 
Join Date: Sep 2023
Posts: 20
roger.stern@mail.com is on a distinguished road
Default Getting VBA Macro to work with a range of cells

I've created a macro to launch the mini date picker when I click on cell A1.
It works.



When I change the range to ("A1:A10") it doesn't work at all. how can I launch the date picker when I click in any cell in a range?


Quote:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' Set the specific cell you want to monitor
Dim MonitoredCell As Range
Set MonitoredCell = Me.Range("A1")

' Check if the newly selected cell is the monitored cell and it's a single cell
If Target.Address = MonitoredCell.Address And Target.Count = 1 Then
ActiveSheet.Shapes("Calendar").Visible = True
ActiveSheet.Shapes("Calendar").Left = ActiveCell.Left + ActiveCell.Width
ActiveSheet.Shapes("Calendar").Top = ActiveCell.Top + ActiveCell.Height


Else

' hide the calendar if a cell is selected outside the Start or Completion Date columns
ActiveSheet.Shapes("Calendar").Visible = False


End If
End Sub
Attached Files
File Type: xlsm Working Test except for range.xlsm (23.0 KB, 1 views)
Reply With Quote
  #2  
Old 10-19-2025, 03:15 PM
macropod's Avatar
macropod macropod is offline Getting VBA Macro to work with a range of cells Windows 10 Getting VBA Macro to work with a range of cells Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,483
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

This works for me:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
With ActiveSheet
  If Intersect(Target, .Range("A1:A10")) Is Nothing Then .Shapes("Calendar").Visible = False: Exit Sub
  If Selection.Cells.Count > 1 Then .Shapes("Calendar").Visible = False: Exit Sub
  .Shapes("Calendar").Visible = True
  .Shapes("Calendar").Left = ActiveCell.Left + ActiveCell.Width
  .Shapes("Calendar").Top = ActiveCell.Top + ActiveCell.Height
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel VLOOKUP - Return cells that are not blank from range of specified cells djlw84 Excel 10 05-09-2022 11:59 AM
Distribute text in one cell across a range of cells (overcoming selection.range.cells.count bug) slaycock Word VBA 0 02-18-2017 07:00 AM
Copying text range of cells to different cells adds an extra line jpb103 Word VBA 2 07-23-2014 12:22 PM
Getting VBA Macro to work with a range of cells Using range object to work with multiple columns kjworduser Word VBA 1 11-01-2013 03:03 AM
Count range cells eliminating merge cells danbenedek Excel 0 06-15-2010 12:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft