+ Reply to Thread
Results 1 to 4 of 4

Thread: Dialogue box to select range for autofill macro

  1. #1
    Registered User
    Join Date
    11-14-2008
    Location
    Brooklyn, NY, USA
    Posts
    52

    Dialogue box to select range for autofill macro

    Hi all,
    I have an autofill macro that copies a formula in one cell to all the cells in a defined range.

    Sub autofill()
    'autofills a formula through range
    '
    
    Range("m3961").autofill Destination:=Range("m3961:m7921"), Type:=xlFillDefault
    
    End Sub
    Currently, I manually edit the macro each time I'm using a unqiue range, but I feel like there is a more efficient way to do this. Any ideas? Is it possible to create a dialogue box that allow me to select the range?

    Thanks in advance for the help.

    Cheers!

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Dialogue box to select range for autofill macro

    Something like this
        Dim rFill  As Range
        On Error Resume Next
        Application.DisplayAlerts = False
        Set rFill = Application.InputBox(Prompt:= _
                                         "Please select a range with your Mouse to be bolded.", _
                                         Title:="SELECT RANGE", Type:=8)
        On Error GoTo 0
        Application.DisplayAlerts = True
        If rRange Is Nothing Then
            Exit Sub
        Else:     Range("m3961").autofill Destination:=rfill, Type:=xlFillDefault
        End If
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Registered User
    Join Date
    11-14-2008
    Location
    Brooklyn, NY, USA
    Posts
    52

    Question Re: Dialogue box to select range for autofill macro

    Roy --- this is great! However, I'm still struggling a bit. When I went to run the macro, I received a
    '424' run-time object required
    This is the code:

    Sub autofill()
    'autofills a formula through range
    '
    
       Dim rFill  As Range
        On Error Resume Next
        Application.DisplayAlerts = False
        Set rFill = Application.InputBox(Prompt:= _
                                         "Please select a range with your Mouse to be bolded.", _
                                         Title:="SELECT RANGE", Type:=8)
        On Error GoTo 0
        Application.DisplayAlerts = True
        If rRange Is Nothing Then
            Exit Sub
        Else:     Range("a2").autofill Destination:=rFill, Type:=xlFillDefault
        End If
    End Sub
    I'm sure I did something to make a bit of a hash of it, but I'm not sure what. Any ideas?

  4. #4
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Dialogue box to select range for autofill macro

    Try keeping your original macro as is, I would change the name from autofill() to myautofill() to avoid possible problems, then

    add this macro to call it
     sub getRange()
    
    Dim rFill  As Range
        On Error Resume Next
        Application.DisplayAlerts = False
        Set rFill = Application.InputBox(Prompt:= _
                                         "Please select a range with your Mouse to be bolded.", _
                                         Title:="SELECT RANGE", Type:=8)
        On Error GoTo 0
        Application.DisplayAlerts = True
        If rRange Is Nothing Then
            Exit Sub
        Else: myautofill
        End If
    End Sub
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0