Set Worksh = Worksheets("SampleWorksheet")
Set myRange = Worksh.Range("F1")
msgbox myRange.Value, , ""   'WORKS: current value in "F1" cell is displayed 
myRange.Value = 100            'DOESNT WORK! : value in cell DOES NOT change

I have no idea - it was supposed to work. Any ideas? Thanks

Are you saving the document?? the following code will work:

Private Sub Command1_Click()

Dim xl
Dim Worksh
Dim xlwbook
    Set xl = CreateObject("Excel.Application")
    Set xlwbook = xl.Workbooks.Open("C:\temp.xls")
    Set Worksh = xlwbook.Sheets.Item(1)
    xl.Visible = True
    Set myRange = Worksh.Range("F1")
    MsgBox myRange.Value, , ""
    myRange.Value = 100
    xl.ActiveWorkbook.Close False, "C:\temp.xls"
End Sub

My code is very simmilar but is in function not in sub. May it be the problem? Maybe from functions you can't edit other cells but the one the function is returning it's value to (the one with formula "=MyFunction() ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.