VBA code ??

G

Guest

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
 
B

Bob Phillips

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)
 
G

Guest

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
 
J

JE McGimpsey

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(...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top