VBA Resize shape according to cell timevalue range

geloader0

Board Regular
Joined
Dec 21, 2022
Messages
52
Office Version
  1. 2016
Platform
  1. Windows
I want to populate my shape according to time range value in 1st Range and 2nd Range cell as shown in the image. Column A is the Range to be populated by the textbox as shown in the image. Thank you. Your help is much appreciated
 

Attachments

  • assadas333.JPG
    assadas333.JPG
    48.1 KB · Views: 11

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Welcome to MrExcel forums.

Your description, about populating the shape/range, doesn't really match your thread subject about resizing the shape.

My understanding is that you want to resize the shape in proportion to the start and end times in F3 and G3, the cell position of the first time cell in A4 and the height of the rows.

VBA Code:
Public Sub Resize_Shape()

    Dim shp As Shape
    Dim baseTimeCell As Range
    Dim startTime As Date, endTime As Date
    
    With ActiveSheet
    
        Set shp = .Shapes(1)
        Set baseTimeCell = .Range("A4")
        startTime = .Range("F3").Value
        endTime = .Range("G3").Value
       
        'Top of shape
        
        shp.Top = baseTimeCell.Top + (baseTimeCell.Height / 60) * DateDiff("n", baseTimeCell.Value, startTime)
        
        'Bottom of shape
        
        shp.Height = baseTimeCell.Top + (baseTimeCell.Height / 60) * DateDiff("n", baseTimeCell.Value, endTime) - shp.Top
        
    End With
    
End Sub
 
Upvote 0
Solution

Hello John_w Good day, This is exactly what I am looking for. Sorry about for misinformation about my thread because this is my first time to post a thread. Thank you so much again.

 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,155
Members
449,208
Latest member
emmac

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