Solved

Macro Code Needs Revision

Posted on 2013-01-19
7
195 Views
Last Modified: 2013-01-19
Hello Experts,

I am using this code...

Sub ClearMeasuringUp()
    If MsgBox("You are about to clear the entire worksheet - Are you sure you want to proceed?", vbYesNo) = vbYes Then
        ActiveSheet.Range("B28:D28,F28:H28,J28:L28,P28").ClearContents
        Application.Goto Reference:="Diameter"
        Selection.ClearContents
    End If
End Sub

Open in new window


After the "Selection.ClearContents" - I need the code to go to cell N7 and type the word "Diameter".

Thank you in advance for your help!

~ Geekamo
0
Comment
Question by:Geekamo
  • 4
  • 3
7 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 38796496
Sub ClearMeasuringUp()
    If MsgBox("You are about to clear the entire worksheet - Are you sure you want to proceed?", vbYesNo) = vbYes Then
        ActiveSheet.Range("B28:D28,F28:H28,J28:L28,P28").ClearContents
        Activesheet.Cells(7, 14).Value = "Diameter"
        Application.Goto Reference:="Diameter"
        Selection.ClearContents
    End If
End Sub
0
 
LVL 1

Author Comment

by:Geekamo
ID: 38797693
@ MartinLiss,

I am now using this code...

Sub ClearMeasuringUp()
    If MsgBox("You are about to clear the entire worksheet - Are you sure you want to proceed?", vbYesNo) = vbYes Then
        ActiveSheet.Range("B28:D28,F28:H28,J28:L28,P28").ClearContents
        ActiveSheet.Cells(27, 14).Value = "Diameter"
        Application.Goto Reference:="Diameter"
        Selection.ClearContents
    End If
End Sub

My original cell reference in my post wasn't correct.  So I see that 27, represents row #, and 14 represents the 14th column.  Mind you I know nothing about code, but can't you just reference the cell via it's cell name N27?

~ Geekamo
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 38797725
Yes, you can

ActiveSheet.Range("A27").Value = "Diameter"

They're both the same and in this case using Range is easier but I've gotten into the habit of using Cells because in the code I write I often have to increment the column and it's much easier to do that with Cells.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:Geekamo
ID: 38797739
@ MartinLiss,

Great, this works perfectly! Ya, I guess for me it's easier seeing the range.  I get by, by reusing pieces of code cause this is all beyond me.

Thanks!

~ Geekamo
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 38797741
If you want to learn you can Google something like Excel VBA tutorial.
0
 
LVL 1

Author Comment

by:Geekamo
ID: 38797745
@ MartinLiss,

Ya, I definitely want to get more into it. I been watching Mr. Excel on YouTube and it's only been after watching some of his videos that things started clicking.  The workbook I'm working on is probably the most advanced one I've done.  I'm super excited!

~ Geekamo
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 38797768
Glad I was able to help.

Marty  - MVP 2009 to 2012
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

930 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now