sammclean23
09-17-2011, 08:34 AM
Hi All,
To introduce myself, my name is Sam and I am from the UK. Currently progressing with a foundation degree whilst working for British Telecom.
Was wondering if anybody can help.
The code as follows does the obvious which is set some variables, write some values to the spreadsheet and bold the headings.
I need to:
- Make sure each time the code is run that the inputted values are written to the next row down to the previous so that it doesnt overwrite the last line. (EDIT: just looked at the code and it is obvious that each time it will always write to the same cell. Can somebody suggest another way to do this so that the above is possible)
Also, im pretty sure the code can be cut down. I would greatly appreciate any help on this.
The code is as follows:
Option Explicit
Sub Cylinder()
Const PI = 3.14
Dim UserRadius As Double
Dim UserHeight As Double
Dim Volume As Double
UserRadius = InputBox("Enter Radius", "Cylinder Radius")
UserHeight = InputBox("Enter Height", "Cylinder Height")
Volume = PI * (UserRadius * UserRadius) * UserHeight
MsgBox "The Volume of the Cylinder = " & Format(Volume, "0.0")
Worksheets("Sheet1").Select
Range("A1").Value = "Radius"
Range("B1").Value = "Height"
Range("C1").Value = "Volume(Cubed)"
Range("A1:C1").Select
Selection.Font.Bold = True
Range("A2").Value = UserRadius
Range("B2").Value = UserHeight
Range("C2").Value = Volume
ActiveCell.Offset(1, 0).Select
End Sub
Thankyou in advance,
Sam
To introduce myself, my name is Sam and I am from the UK. Currently progressing with a foundation degree whilst working for British Telecom.
Was wondering if anybody can help.
The code as follows does the obvious which is set some variables, write some values to the spreadsheet and bold the headings.
I need to:
- Make sure each time the code is run that the inputted values are written to the next row down to the previous so that it doesnt overwrite the last line. (EDIT: just looked at the code and it is obvious that each time it will always write to the same cell. Can somebody suggest another way to do this so that the above is possible)
Also, im pretty sure the code can be cut down. I would greatly appreciate any help on this.
The code is as follows:
Option Explicit
Sub Cylinder()
Const PI = 3.14
Dim UserRadius As Double
Dim UserHeight As Double
Dim Volume As Double
UserRadius = InputBox("Enter Radius", "Cylinder Radius")
UserHeight = InputBox("Enter Height", "Cylinder Height")
Volume = PI * (UserRadius * UserRadius) * UserHeight
MsgBox "The Volume of the Cylinder = " & Format(Volume, "0.0")
Worksheets("Sheet1").Select
Range("A1").Value = "Radius"
Range("B1").Value = "Height"
Range("C1").Value = "Volume(Cubed)"
Range("A1:C1").Select
Selection.Font.Bold = True
Range("A2").Value = UserRadius
Range("B2").Value = UserHeight
Range("C2").Value = Volume
ActiveCell.Offset(1, 0).Select
End Sub
Thankyou in advance,
Sam