View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
FamilyGuy902 FamilyGuy902 is offline
external usenet poster
 
Posts: 2
Default Recording Macro - Excel makes reference to a specific cell

Hi. I have recorded my first excel Macro. I am trying to copy/ paste
a cell down
for as many rows that are in my file. However, as shown in the
following code, it is making reference to cell B42, which happens to
be the end of the file (i.e. End-Down) that I used to record the
macro. It causes
my macro to not work properly if there are a different amount of rows
in my file. Each file I use will have a different amount of rows.

Does anyone know what sequence of actions I should use when recording
the macro -- to prevent specific cells from being referenced?

Or. can someone who understands Visual Basic take a stab at
correcting my code so that it will work with any amount of rows.
Thanks in advance.

Sub TestMacro()
Range("B2").Select
ActiveCell.FormulaR1C1 = "=UPPER(RC[-1])"
Range("B2").Select
Selection.Copy
Range("A2").Select
Selection.End(xlDown).Select
Range("B42").Select
Range(Selection, Selection.End(xlUp)).Select
Range("B3:B42").Select
Range("B42").Activate
ActiveSheet.Paste
End Sub