+ Reply to Thread
Results 1 to 3 of 3

Format Dependent on Input Type

Hybrid View

  1. #1
    Registered User
    Join Date
    02-26-2019
    Location
    Minnesota
    MS-Off Ver
    365
    Posts
    2

    Question Format Dependent on Input Type

    I have a block of cells that need to be "Center Justified" with "Shrink To Fit" when numbers are inputted and "Left Justified" with "Shrink to Fit" removed when text is inputted. The columns and rows are both summed so the text input needs to be ignored by the sum function. Is this doable? Easy?

    Thanks,
    Pete

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,984

    Re: Format Dependent on Input Type

    You could use a worksheet_change event, assuming these are manual entries:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim MonitoredRange As Range
        ' change as required
        Set MonitoredRange = Range("A1:B5")
    
        If Not Intersect(Target, MonitoredRange) Is Nothing Then
            Application.ScreenUpdating = False
            Dim cell As Range
            For Each cell In Intersect(Target, MonitoredRange).Cells
                If IsNumeric(cell.Value2) Then
                    With cell
                        .HorizontalAlignment = xlCenter
                        .ShrinkToFit = True
    
                    End With
                Else
                    With cell
                        .HorizontalAlignment = xlLeft
                        .ShrinkToFit = False
                    End With
                End If
            Next cell
        End If
    
    End Sub
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    02-26-2019
    Location
    Minnesota
    MS-Off Ver
    365
    Posts
    2

    Re: Format Dependent on Input Type

    Thanks!!!!!! Exactly what i was looking for.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Dependent List: select option or type text
    By mazcarate in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 05-30-2017, 04:56 PM
  2. Replies: 3
    Last Post: 02-24-2015, 02:58 AM
  3. Input box to needs different type of variable type (RC vs. A1?)
    By Niedermee in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-18-2014, 05:00 PM
  4. [SOLVED] Dependent Validation Type
    By Excel_Beginner_1234 in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 06-09-2013, 05:45 AM
  5. Proper handling of "cancel" for range-type input box response (type 8)
    By MCCCLXXXV in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-28-2011, 11:19 AM
  6. Type mismatch using rnge as Range with Type 8 Input Box
    By STEVE BELL in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-03-2005, 01:10 AM
  7. Adding new 'Type' to Format->Number->Time->Type
    By Alex Vinokur in forum Excel General
    Replies: 5
    Last Post: 09-26-2005, 04:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1