PDA

View Full Version : Help plotting a graph in VBA



AleemAM123
12-05-2010, 05:32 AM
Hi Everyone, having some problems with som code I found online.

The document can be found here:
http://www.scribd.com/doc/7010865/How-Excel-is-Used-for-Undergraduate-Chemical-Engineers

And I have included an excel sheet. The calulations work but it doesn't plot the chart. I'm not familiar with charts in VBA. Would appreciate any help, thanks.

AleemAM123
12-05-2010, 08:54 AM
Oh guessing something in here isn't working:




Private Sub PlotChart()
Dim N As Integer, rng As Range
N = [SN]
Set rng = Range("Z1")
rng.Offset(N, 0).Value = [SN].Value
rng.Offset(N, 1).Value = [TC].Value
rng.Offset(N, 2).Value = [x].Cells(1, 1).Value
rng.Offset(N, 3).Value = [x].Cells(2, 1).Value
rng.Offset(N, 4).Value = [x].Cells(3, 1).Value
rng.Offset(N, 5).Value = [y].Cells(1, 1).Value
rng.Offset(N, 6).Value = [y].Cells(2, 1).Value
rng.Offset(N, 7).Value = [y].Cells(3, 1).Value
End Sub



Excel 2003 version file attached.

Bob Phillips
12-05-2010, 11:43 AM
There is no chart in the workbook, so it cannot update.

AleemAM123
12-05-2010, 06:51 PM
:jawdown: wow! ha... lol I guess I thought with that plot graph function it was supposed to plot itself. Thanks for that bit of info XLD. Weird though that he is wiping the data out so quickly after generating the table for the graph.

Oh I have some questions on the code, not sure why it was done and this might help me understand VB a little better.

Why is this statement declared up top

Dim Stripping As Boolean


and what is the purpose of Flag: ? is it a marker to get back to a point in the code?


Public Sub Main()
Naming
Flag:
BubblePoint
If [y.Bz] >= [xD.Bz] Then GoTo GettingOut
ChangeX
If Stripping Then Verify
GoTo Flag
GettingOut:
BubblePoint
End Sub