+ Reply to Thread
Results 1 to 5 of 5

Ceiling function and drag and drop

Hybrid View

  1. #1
    Registered User
    Join Date
    04-13-2015
    Location
    Luanda
    MS-Off Ver
    Vista
    Posts
    43

    Question Ceiling function and drag and drop

    Hi guys,
    I have this formula in which I want to things:
    1* In my spreadsheet the first formula, does the upper case function, but if I try to drag and drop in that range, it gives and error in VBA.
    2* In the same spreadsheet the second formula, works to turn decimal into duration by round it, but I want to add a round of multiple of 15, thing that I can do in a normal excel sheet using the "=Ceiling(E15,15)".
    ... SO, I want to apply the Ceiling in this formula, without taking off the round function which is already there.
    here is the formula:

    Private Sub Worksheet_Change(ByVal target As Range)
        If Not (Application.Intersect(target, Range("C:D")) _
          Is Nothing) Then
            With target
                If Not .HasFormula Then
                    Application.EnableEvents = False
                    .Value = UCase(.Value)
                    Application.EnableEvents = True
                End If
            End With
        End If
        If Not (Application.Intersect(target, Range("E5:E10005")) _
          Is Nothing) Then
            With target
                If Not .HasFormula Then
                    Application.EnableEvents = False
                    .Value = "0:" & Round(.Value * 60, 0)
                    Application.EnableEvents = True
                End If
            End With
            End If
            End Sub

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Ceiling function and drag and drop

    Private Sub Worksheet_Change(ByVal target As Range)
    
    If Not Intersect(target, Union(Range("C:D"), Range("E5:E10005"))) Is Nothing Then
        Dim r As Range
    
        For Each r In target.Cells
            If Not Application.Intersect(target, Range("C:D")) Is Nothing Then
                With r
                    If Not .HasFormula Then
                        Application.EnableEvents = False
                        .Value = UCase(.Value)
                        Application.EnableEvents = True
                    End If
                End With
            End If
            If Not (Application.Intersect(r, Range("E5:E10005")) Is Nothing) Then
                With r
                    If Not .HasFormula Then
                        Application.EnableEvents = False
                        .Value = "0:" & Application.Ceiling(Round(.Value * 60, 0), 15)
                        Application.EnableEvents = True
                    End If
                End With
            End If
        Next r
    End If
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,308

    Re: Ceiling function and drag and drop

    Your code is designed to cater for a single cell (Target cell) change. If you drag a formula down a column (of interest) then you will be making changes to multiple cells ...

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range
    
    'Stop
    
    ' cater for clearing entire column(s)
    If Target.Rows.Count = Me.Rows.Count Then Exit Sub
    
    If Not (Application.Intersect(Target, Range("C:D")) _
        Is Nothing) Then
        For Each cell In Target
            With cell
                If Not .HasFormula Then
                    Application.EnableEvents = False
                    .Value = UCase(.Value)
                    Application.EnableEvents = True
                End If
            End With
        Next 'cell
    End If
    
    If Not (Application.Intersect(Target, Range("E5:E10005")) _
        Is Nothing) Then
        For Each cell In Target
            With cell
                If Not .HasFormula Then
                    Application.EnableEvents = False
                    .Value = "0:" & Round(.Value * 60, 0)
                    Application.EnableEvents = True
                End If
            End With
        Next 'cell
    End If
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    04-13-2015
    Location
    Luanda
    MS-Off Ver
    Vista
    Posts
    43

    Re: Ceiling function and drag and drop

    Quote Originally Posted by TMS View Post
    Your code is designed to cater for a single cell (Target cell) change. If you drag a formula down a column (of interest) then you will be making changes to multiple cells ...

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range
    
    'Stop
    
    ' cater for clearing entire column(s)
    If Target.Rows.Count = Me.Rows.Count Then Exit Sub
    
    If Not (Application.Intersect(Target, Range("C:D")) _
        Is Nothing) Then
        For Each cell In Target
            With cell
                If Not .HasFormula Then
                    Application.EnableEvents = False
                    .Value = UCase(.Value)
                    Application.EnableEvents = True
                End If
            End With
        Next 'cell
    End If
    
    If Not (Application.Intersect(Target, Range("E5:E10005")) _
        Is Nothing) Then
        For Each cell In Target
            With cell
                If Not .HasFormula Then
                    Application.EnableEvents = False
                    .Value = "0:" & Round(.Value * 60, 0)
                    Application.EnableEvents = True
                End If
            End With
        Next 'cell
    End If
    End Sub

    Regards, TMS
    Thanks so much, its working perfectly the first problem if had.
    Please, explain to me how to avoid this for next time I may create a macro.
    Last edited by Isaacadete; 06-11-2015 at 09:16 AM.

  5. #5
    Registered User
    Join Date
    04-13-2015
    Location
    Luanda
    MS-Off Ver
    Vista
    Posts
    43

    Re: Ceiling function and drag and drop

    Quote Originally Posted by Isaacadete View Post
    Hi guys,
    I have this formula in which I want to things:
    1* In my spreadsheet the first formula, does the upper case function, but if I try to drag and drop in that range, it gives and error in VBA.
    2* In the same spreadsheet the second formula, works to turn decimal into duration by round it, but I want to add a round of multiple of 15, thing that I can do in a normal excel sheet using the "=Ceiling(E15,15)".
    ... SO, I want to apply the Ceiling in this formula, without taking off the round function which is already there.
    here is the formula:

    Private Sub Worksheet_Change(ByVal target As Range)
        If Not (Application.Intersect(target, Range("C:D")) _
          Is Nothing) Then
            With target
                If Not .HasFormula Then
                    Application.EnableEvents = False
                    .Value = UCase(.Value)
                    Application.EnableEvents = True
                End If
            End With
        End If
        If Not (Application.Intersect(target, Range("E5:E10005")) _
          Is Nothing) Then
            With target
                If Not .HasFormula Then
                    Application.EnableEvents = False
                    .Value = "0:" & Round(.Value * 60, 0)
                    Application.EnableEvents = True
                End If
            End With
            End If
            End Sub
    It's so awesome, please explain to me how you done, so the next time I might be able to do it so.

+ 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. Use of CEILING Function
    By IMA_Saihat in forum Tips and Tutorials
    Replies: 3
    Last Post: 04-12-2015, 05:17 AM
  2. Replies: 2
    Last Post: 09-19-2012, 11:44 AM
  3. Same function / different area (w/ drag and drop)
    By ServerBTest002 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-02-2011, 08:02 PM
  4. How to contorl drag and drop function for a particular xls
    By arunvmohan in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 11-09-2006, 03:31 PM
  5. HELP with AddrOf function for Drag-n-Drop
    By Barmaley in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2005, 09:06 AM

Tags for this Thread

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