Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Clear a Range in VBA - Excel 2007

Posted on 2012-04-04
4
559 Views
Last Modified: 2012-06-27
Hi,

In the below code before it retrieves the data I need it to clear the data that is in a range named 'ClearDataRange'.


Open in new window

Sub GetData()

    'ActiveSheet.Unprotect

    X = EssVSetSheetOption(Null, 5, 1)
    Y = EssVSetSheetOption(Null, 11, True)
    X = EssVSetSheetOption(Null, 12, False)
    X = EssVSetSheetOption(Null, 13, True)
    X = EssVSetSheetOption(Null, 14, "Default")
    X = EssVSetSheetOption(Null, 18, False)
    X = EssVSetSheetOption(Null, 24, False)
    X = EssVSetSheetOption(Null, 25, False)


    X = EssVRetrieve(Null, Range("Retrieve_Data"), 1)
    If X = 0 Then
        MsgBox ("     Data Retrieve Successful.")
    Else
        MsgBox ("Retrieve Failed. Please try again.")
    End If

    Range("C15").Select
    'ActiveSheet.Protect

End Sub

Open in new window

0
Comment
Question by:elwayisgod
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:kgerb
ID: 37808458
This will clear your named range

Range("ClearDataRange").Clear

Kyle
0
 

Author Comment

by:elwayisgod
ID: 37808468
Yep.  And it took my formatting with it :(   Forgot to put that stipulation in there :)
0
 
LVL 12

Accepted Solution

by:
kgerb earned 500 total points
ID: 37808476
oops, sorry,  In that case do...

Range("ClearDataRange").ClearContents

Kyle
0
 

Author Closing Comment

by:elwayisgod
ID: 37808496
Perfect Thanks!!!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question