Thread: VBA code ??
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default VBA code ??

You didn't incorporate all of Bob's changes. Instead of

Cells(...)

which defaults to the active sheet, you need to use the qualified

.Cells(...)

In article ,
Paul wrote:

Thanks Bob Phillips,

it still works on the datax page but not when another sheet is active. here
is all the code along with your suggested change:

Sub alt_ma780()
Dim beginrow As Integer
Dim FRML As String
Dim ma As Integer
ma = InputBox("ENTER MA", "# MA ROWS", 500)
If ma < 10 Then End
Worksheets("DATAX").Cells(1, 9) = "DELTA " & ma
beginrow = ma + 3
FRML = "=((I" & beginrow - 1 & "*" & ma & ")-F3+F" & beginrow & ")/" & ma
With Worksheets("DATAX")
.Range(Cells(3, 9), Cells(beginrow - 1, 9)).Formula =
Worksheets("DATAX").Cells(3, 9).Formula
End With
Worksheets("DATAX").Cells(beginrow, 9).Formula = FRML
Worksheets("DATAX").Range(Cells(beginrow, 9), Cells(4015, 9)).Formula =
Worksheets("DATAX").Cells(beginrow, 9).Formula
End Sub




"Bob Phillips" wrote:

With Worksheets("DATAX")
.Range(.Cells(3, 9), .Cells(beginrow - 1, 9)).Formula =
.Cells(3, 9).Formula
End With

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Paul" wrote in message
...
The following code works when the DATAX sheet is activated; but when
another
sheet is selected/activated, it generates an error "1004
Application-defined or Object-defined error"

can someone tell me what I did wrong??

Worksheets("DATAX").Range(Cells(3, 9), Cells(beginrow - 1, 9)).Formula =
Worksheets("DATAX").Cells(3, 9).Formula