knightrider Posted November 14, 2012 Posted November 14, 2012 Morning, I am trying to get a field on a excel file to increase each time the file is opened. Attached is the file and I have tried inserting the following code into it. Private Sub Workbook_Open() Range("F3").Value = 1 + Range("F3").Value End Sub This I thought would increase the value of the cell by 1 each time the file is opened. However this isn't working and i have no idea why. I am literally ripping my hair out over this. I'm sure it’s really simple to do. Any help much much appreciated. KnightriderMaster1.xlsx
Geoff Posted November 14, 2012 Posted November 14, 2012 I think you have to reference the worksheet too? Worksheets("Sheet1").Range("A1").Value = Worksheets("Sheet1").Range("A1").Value + 1
Steve21 Posted November 14, 2012 Posted November 14, 2012 (edited) There's your issue "Master1.xlsx" That's not a macro enabled file. It'll need to be a .xlsm Just tested it and Private Sub Workbook_Open() Range("F3").Value = Range("F3").Value + 1 End Sub In my test.xlsm using "Thisworkbook" and it works fine Steve Edited November 14, 2012 by Steve21
Stuart_C Posted November 14, 2012 Posted November 14, 2012 (edited) I've copied your code into a workbook and it runs OK. How about changing the name of the Sub to "AutoOpen" so it runs everytime it runs when the workbook opens. Possibly change it to an xlsm file which is what I've saved it as? Blast beaten too it! Edited November 14, 2012 by Stuart_C
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now