Thread: Basic Stuff.
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Kevin Stecyk Kevin Stecyk is offline
external usenet poster
 
Posts: 74
Default Basic Stuff.

Hi Brian,

It's good to see you again.

I had assumed (always dangerous) that if a person was asking about
programming questions, he or she has at least gotten to the VBE editor.

But maybe that was too big of a leap?

I am using XL 2000, but I think the instructions will apply to your version
as well.

Here's what you do:

1) Start Excel
2) Go to Sheet1
3) Go to Cell A1 and insert numerical 5
4) Alt-F11 (or Tools | Macro | Visual Basic Editor....takes you to the
Visual Basic Editor)
5) Insert Module
6) Copy and paste code (I will provide code again at the end).
7) Alt-Q (or File | Return and Close to Microsoft Excel)
8) Alt-F8 (or Tools | Macro | Macros)
9) You can choose to Step Into or Run at this point

10) If you choose to Step Into....you will be taken back to VBE. In VBE you
can press F8 or use the toolbar to execute each line of code.
10 A) As you move through each line of code, have a look the spreadsheet to
see the changes.

You are done.

This is a very, very simple subroutine. It merely demonstrates....

a) Assigning a value from a cell to a visual basic variable
b) Assigning a value from a visual basic variable to a cell
c) Assiging a string "B1:D1" to a variable which was used to define a range.

You should look up in XL's help on Dim (dimension) variables. You should
note that I would have been better to use Dim Var1 as a variant rather than
as a double. That way, any value could be placed in A1. However, I used
double so that most numerical values could be placed in A1.

Also, the '\ are simply comments. VBA requires only the single apostrophe
to designate a comment. Whatever follows the single apostrophe is
considered a comment. However, I use '\ because it is easier to see it. It
stands out more. The backslash is merely part of the comment.

Sub Test1()
Dim dVar1 As Double
Dim sImportantRange As String

'\ Silly example to demonstrate some basic concepts
'\ "A1" on Sheet1 has the numerical value 5

sImportantRange = "B1:D1"

dVar1 = Sheets("Sheet1").Range("A1").Value

Sheets("Sheet1").Range("A2").Value = dVar1

Sheets("Sheet1").Range(sImportantRange).Value = dVar1

End Sub

I hope that helps.

Regards,
Kevin




"Brian Tozer" wrote in message:

Lack of totally explicit instructions on how to implement the above

example
in my Excel 2002.