• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

pausing macro

Dalia

Member
hi,

i want to pause a macro and select a range.w hen am giving activecell. address in default its happening but when i give range.select in default its not happening. i want to understand why not. kindly help
and i also want to know if there is a data in the range i selected and i want to clear it and insert the userrange how to do that
Code:
Sub macro2()
'pausing macro
Dim userrange As Range
Dim prompt As String
Dim title As String
prompt = "enter the name"
title = "name"
'the below line where u find default:= range.select is not happening
Set userrange = Application.InputBox(prompt:=prompt, title:=title, Default:=Range.Select, Type:=8)
If userrange = "" Then
MsgBox "cancelled"
Else
userrange = "=rand()"
End If
 
Hello Dalia
Try this code
Code:
Sub Test()
    Dim UserRange As Range
    Dim strPrompt As String, strTitle As String
    strPrompt = "Enter The Name"
    strTitle = "Name"
    On Error Resume Next

    Set UserRange = Application.InputBox(Prompt:=strPrompt, Title:=strTitle, Default:=Selection.Address, Type:=8)

    If TypeName(UserRange) <> "Range" Then
        MsgBox "Cancelled"
    Else
        UserRange = "=RAND()"
    End If
End Sub
 
Back
Top