I have a Mileage chart (I will attach it) and what
I wanted to be able to do (if possible) is to be able to click on the
amount of mileage (such as in cell F5) and that number be entered into
one cell (cell F11 on the Travel Form). I also would like for the
appropriate row heading (in this case Dewar Elementary) to appear in
another (cell B11 on travel form), and the column header (in this case
Hahira Elementary) to appear in cell c11 on the travel form.
Open the mileage chart. Along the bottom of the Excel window are "tabs"
representing the worksheets in each workbook. Since you haven't done
anything to change them, they're the default: Sheet1, Sheet2, Sheet3.
The mileage chart is in sheet1.
Right-click on the Sheet1 tab and choose View Code. This opens the
Visual Basic (VB) editor window. VB is a programming language built into
Excel (and other Microsoft programs). The window should be titled
"Microsoft Visual Basic - Mileage Chart.xls - [Sheet1 (Code)]. "Code"
means the instructions that tell the computer what to do.
In the main area of the window, which is blank, type the following:
Option Explicit
Const travelform As String = "Travel form (2).xls"
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Integer
Dim r As Long
If Target.Count > 1 Then Exit Sub
c = Target.Column
r = Target.Row
If c < 2 Or c > 13 Or r < 3 Or r > 14 Then Exit Sub
Workbooks(travelform).ActiveSheet.Range("F11") = Target.Value
Workbooks(travelform).ActiveSheet.Range("C11") = Cells(2, c).Value
Workbooks(travelform).ActiveSheet.Range("B11") = Cells(r, 1).Value
End Sub
This subroutine is executed each time you click on a cell in the mileage
chart -- that's what the "SelectionChange" means. Target is a
representation of the cell you clicked on. After some initial processing
to determine whether you actually clicked on a mileage, it copies the
information to the other workbook.
See if you can understand what is going on. It should be simple to
modify the script if you want it to do something different.
Thanks for your response to my question. I know just enough about
excel functions to really confuse myself. I don't know what you
mean by OLE or VB?
OLE stands for "Object Linking and Embedding". It is a way of putting
objects (menus, buttons, pictures, etc.) into a document such as an Excel
spreadsheet or a Word file. My thought was to create buttons with all
the mileage amounts on them, and clicking the button updates the
necessary cells.
VB stands for Visual Basic. It is the programming language built into
Excel that can control all kinds of aspects of Excel.