Jump to content

Recommended Posts

Posted

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.

 

Knightrider

Master1.xlsx

Posted

I think you have to reference the worksheet too?

 

Worksheets("Sheet1").Range("A1").Value = Worksheets("Sheet1").Range("A1").Value + 1

Posted (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 by Steve21
Posted (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 by Stuart_C

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...