Jeeped,
I fully understand what you are saying about recording a sub vs. writing the proper sub code. That is why I am reading everything I can get my hands on to teach myself how to work directly with VBA.
Here is the code that the macro recorder produced when I recorded the series of keystrokes shown below the macro code.
------------ macro code begin ------------
Sub Macro3()
'
' Macro3 Macro
' This macro will replace the text in the first line of each data block, in column E
' with a link to the total miles cell at the end of each data block, in column H.
' After replacing the text, the macro will move the cursor to the first line of the
' next data block where the macro will be re-run (Ctrl+Shift+L). This will continue
' until the last data block in the file has been edited.
'
' Keyboard Shortcut: Ctrl+Shift+L
'
ActiveCell.FormulaR1C1 = "=R[7]C[3]"
Selection.End(xlDown).Select
End Sub
------------ macro code end ------------
------------ macro keystrokes begin ------------
- I place the cursor in cell on the first line of a data block in column E, I type "="
- I then move the cursor to the right three cells using the key.
- I then move the cursor to the last line of the data block by pressing Ctrl+▼two times.
- I then press ENTER to complete the link function
- After pressing ENTER the cursor is moved back to the original cell where I typed "="
- I then position the cursor on the first line of the next data block directly below that data block that was just edited by pressing Ctrl+▼ once.
- I then re-execute the macro by typing Ctrl+Shift+L.
------------ macro keystrokes end ------------
I want to repeat this for each data block until the last data block at the end of the file has been edited in this way. However if a macro can be written to make this edit on every data block in the file without having to
re-run the macro for each data block that would be even better.
As I described in my original post, the number of rows for each data block is variable and unlike the cursor movement in step number 2 above which is always three cells to the right, I can't just specify a set number of
rows to move down. To get around this I attempted to record the Ctrl+▼
key combination because, as you know, this key combination moves the cursor to the next cell in the column containing data. However, when played back, the macro moves the cursor down the exact number of rows that Ctrl+▼moved the cursor when the macro was recorded, even when relative references is turned on.
Thanks again for your help,
Dan