Results 1 to 10 of 15

Thread: Align TextBox Within A Range

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    May 2020
    Posts
    66
    Rep Power
    5

    Align TextBox Within A Range

    Hi!
    My sheet have a text box named "TextBox 2" which is placed in the Range("B356:Z375"). The sheet contains a macro to auto fit the textbox within the same Range("A356:A375") irrespective of the height of the textbox, means, if the textbox is resized due to entry of texts, the rows adjust itself to fit with the height of the textbox. The minimum height of the textbox is fixed as 171.
    (Please see the attachment below)

    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
                 
    'Overall Observation
        If Target.Cells.Count = 1 And IsEmpty(Target) Or Not IsEmpty(Target) Then
           If ActiveSheet.Shapes("TextBox 2").Height < 171 Then
               Let ActiveSheet.Shapes("TextBox 2").Height = 171
               Range("A356:A375").RowHeight = ActiveSheet.Shapes("TextBox 2").Height / 20
             Else
               Range("A356:A375").RowHeight = ActiveSheet.Shapes("TextBox 2").Height / 20
           End If
        End If
        
    End Sub
    Problem:
    1. The macro above is running on selection of any cell on the sheet, which, I think, will create unnecessary burden on the system. It should run only after selection of the textbox.

    2. Rows are not adjusted exactly as the height of textbox, i.e., text box height is moving a little bit inside or outside of the Range("A356:A375") in bottom, when the height is changed after entering text in the textbox.


    Solution of Problem No. 2
    One solution, I think, is to readjust the height of the textbox to align it with the Range("A356:A375") or between the row (356:375).

    With Thanks!
    Anshu

    P.S.
    I've noticed a strange thing. The UNDO and REDO option is not working due to this Macro.I don't understand what the hell is going on!
    Attached Files Attached Files
    Last edited by Anshu; 10-10-2020 at 08:53 PM.

Similar Threads

  1. Align Data In Groups Of Columns
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 0
    Last Post: 05-25-2015, 03:07 AM
  2. Replies: 4
    Last Post: 11-15-2013, 03:42 PM
  3. Replies: 9
    Last Post: 08-08-2013, 07:13 PM
  4. Align Shapes (Charts) On ActiveWorksheet
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 1
    Last Post: 05-14-2012, 03:25 AM
  5. Replies: 2
    Last Post: 02-29-2012, 08:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •