PDA

View Full Version : Computers Need VBA help


Tylerthigpen!1!
02-11-2010, 02:46 AM
Ugh it's the most basic code and I'm having problems. Basically writing a macro to convert kilograms (B2) to newtons (B4). Anybody care to look over my 4 lines of code? I'm getting a sub of function not defined error. It highlights sub weight. This is for my engineering class.

Option Explicit
Dim M As Double 'Creates M, Mass in kilograms
Dim W As Double 'Creates w, Weight in Newtons
Sub Weight() ' Start


'Input M
M = Rang("B2").Value

'Calculate W
W = 9.8 * M

'Output W
Rang("B4").Value = W


End Sub ' End

Tylerthigpen!1!
02-11-2010, 03:36 AM
ah forgot the e's on range :doh!:

BigRedChief
02-11-2010, 10:16 AM
Ugh it's the most basic code and I'm having problems. Basically writing a macro to convert kilograms (B2) to newtons (B4). Anybody care to look over my 4 lines of code? I'm getting a sub of function not defined error. It highlights sub weight. This is for my engineering class.

Option Explicit
Dim M As Double 'Creates M, Mass in kilograms
Dim W As Double 'Creates w, Weight in Newtons
Sub Weight() ' Start


'Input M
M = Rang("B2").Value

'Calculate W
W = 9.8 * M

'Output W
Rang("B4").Value = W


End Sub ' End
Looks like a typo to me