Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a file and manipluate cells

Status
Not open for further replies.

ckaren000

Technical User
Aug 31, 2003
7
US
Hi people,
i am writing a simple macro in excel but i don't know what i am doin wrong.
here is the thing i wanted to do,
open a file (temp.xls) and manipluate some cell data. i created a button in a file and inputed following code
Private Sub CBopen_Click()
Workbooks.Open Filename:="C:\temp.xls"
Workbooks("temp.xls").Activate
Worksheets("sheet1").Activate
Range("E10").Select
ActiveCell.FormulaR1C1 = "=RC[-3]-5"
Range("F10").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*100"
Range("E10:F10").Select
End Sub
but it gives error saying "select method of Range class failed" ( its giving error at "Range("E10").Select ").
i think i am not able to point excel to right workbook.
thanks in advance for the help.
regards
karen
 
You problem was that the Sheet1, where the ranges E10:F10 were to be selected was Active, but it wasn't Selected. You don't need to do all of that anyway:

Here is a better way to do what you wanted:
Code:
Private Sub CBopen_Click()
Workbooks.Open Filename:="C:\temp.xls"
Workbooks("temp.xls").Sheet1.[E10].FormulaR1C1 = "=RC[-3]-5"
Workbooks("temp.xls").Sheet1.[F10].FormulaR1C1 = "=RC[-3]*100"
With Workbooks("temp.xls")
    .Select
    .Sheet1.select
End With
End Sub

I hope this helps!


Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
I also noticed that this was your first post in Tek-Tips.

Welcome!! [thumbsup2]

[rockband]

I hope that your first experience was a good one!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
thanks Mike. but i tried it, still its not working. it gives this error 'object dosent' support this property or method' it gave error at Workbooks("temp.xls").Sheet1.[E10].FormulaR1C1 = "=RC[-3]-5". i rightclicked on it and clicked the definition then it gave a message saying
' cannot jump to Workbooks because it is hidden' is it because of this code is not working. i don't know how to unhide it.

but when i use the code which i used earlier(the one on top) it dosent give error at workbook.
thanks
Karen

 
I'm sorry about that, I don't know what I was thinking. [blush]

Code:
Private Sub CBopen2_Click()
Workbooks.Open FileName:="C:\temp.xls"
Workbooks("temp.xls").Sheets("Sheet1").Range("E10").FormulaR1C1 = "=RC[-3]-5"
Workbooks("temp.xls").Sheets("Sheet1").Range("F10").FormulaR1C1 = "=RC[-3]*100"
Workbooks("temp.xls").Activate
End Sub

I hope this helps!

Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
ckaren000,

I'm glad it worked, and I'm glad I could help (even though it took two tries [blush])

I know that you're new to the forums, so I figured that I would inform you that the traditional way to thank someone in the forums is to award them a star if you found their solution helpful.

To do this click the link Mark this post as a helpful/expert post! at the bottom left hand side of the post that helped you.

You don't have to be the one who asked the question to award a star either, if you do a keyword search in the formus and find a post that is helpful to you, you can award that member a star for his solution.

Thanks! And once again, WELCOME! [thumbsup2]



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top