Solved

Macro Code Needs Revision

Posted on 2013-01-19
7
219 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
[X]
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
  • 4
  • 3
7 Comments
 
LVL 48

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 48

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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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 48

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 48

Expert Comment

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

Marty  - MVP 2009 to 2012
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

636 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