km1234
km1234

Reputation: 2319

Dynamically change charts in excel

I have the following problem. I have a relative large number of excel charts, and I want to be able to change the size of the charts (i.e. width and height) automatically. By automatically I mean the following: I have two cells, one for height and one for width, and when I change them, the charts change automatically, without having to push any other button or anything. For example, cell A1 has the value 100 for width and cell B1 has the value 200 for the height. So, when I change A1 to 200 and B1 to 300 I get all my charts to get bigger.

what I have done up to now is to be able to loop over all charts, and change the shapes, but I need to hit a button first for my macro to run. I would like to find out if there is a way to change the shape of the charts without having to push any button, just by changing the values of the two cells that have the width and the height of the charts. Thanks in advance.

Upvotes: 2

Views: 131

Answers (1)

Gotrekk
Gotrekk

Reputation: 494

in vbaproject, open microsoft excel objects and select the Sheet where you have your A1:B1 in. Then write

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Target.Worksheet.Range("A1:B1")) Is Nothing Then
'put your macro here'
    End If
End Sub

this way, everytime something changes in A1 or B1 you get your macro to run. Be careful of what you write in A1 or B1 tho, you should put some checks on those values before you run your macro

Upvotes: 1

Related Questions