# Graph an ln function

#### sarahrosenberg

##### Board Regular
I need to creat a graph using an ln function, and am not sure how to do this in Excel 2007.

My formula is y=-0.25ln(x)+1 How do I tell Excel to put this in a graph, or can I?

### Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Do you have a list of values for x?

I do - is that how I need to graph it?

Yes, you need to create a y value for each x value, using your formula.

HTH. Dave
Code:
``````Sub ChartFunction()
'charts function on sheet 1
Dim ChartRange As Range, Xvalue As Range, Yvalue As Range, Increment As Double
Dim Xmin As Double, Xmax As Double, Iter As Integer, Cnt As Integer

Application.ScreenUpdating = False
'change values below to suit
Iter = 100 'Number of chart points
Xmin = 0.001 'lowest "X" value *** > 0 for this eg.
Xmax = 10 'highest "X" value

'chrt pt increments
Increment = (Xmax - Xmin) / (Iter - 1)

On Error Resume Next
'make chart y data with f(x)
For Cnt = 1 To Iter
Sheets("sheet1").Cells(Cnt, 1) = Xmin '"X" value
' "Y" value generated by function for "X" value eg. 2 * Sin(3 * Xmin) + 8
'Sheets("sheet1").Cells(Cnt, 2) = ((-7) * (3 * Xmin ^ 2)) + (2 * Xmin / 5) - 6
'Sheets("sheet1").Cells(Cnt, 2) = 2 * Sin(3 * Xmin) + 8
Sheets("sheet1").Cells(Cnt, 2) = Application.WorksheetFunction.Ln(Xmin) * -0.25 + 1
Xmin = Xmin + Increment
Next Cnt
'make chart
Set Xvalue = Sheets("sheet1").Cells(1, 1)
Set Yvalue = Sheets("sheet1").Cells(Iter, 2)
Set ChartRange = Sheets("sheet1").Range(Xvalue, Yvalue)
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SetSourceData Source:=ChartRange, PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
Application.ScreenUpdating = True
End Sub``````

Replies
2
Views
126
Replies
1
Views
78
Replies
1
Views
80
Replies
5
Views
212
Replies
1
Views
165

1,196,510
Messages
6,015,624
Members
441,912
Latest member
Rayna_rahman00

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back