Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Yes, I'm an idiot...But I cannot seem to divide two values in VBA see below

Obviously I'm a ultra newbie to this. I tried searching this group and
find stuff that is close, but not what I need. If fear that I am
looking for something that is so easy, that everyone else has figured
it out. Hence, I cannot find the right solution.

See below for the oh so eloquent abortion of code that I have brought
together.

Dim span As Range
Dim divisions As Range
Set span.Value = Worksheets("Sheet1").Range("G20")
Set divisions.Value = Worksheets("Sheet1").Range("E20")
Set answer.Value = span.Value / divisions.Value
Worksheets("Sheet1").Range("J20").Value = answer.Value

Now that I have the masses writhing in pain from my stupidity, could
someone rectify the situation for this dolt.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Yes, I'm an idiot...But I cannot seem to divide two values in VBA see below

Try

Set span = Worksheets("Sheet1").Range("G20")
Set divisions = Worksheets("Sheet1").Range("E20")
answer= span.Value / divisions.Value
Worksheets("Sheet1").Range("J20").Value = answer


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



wrote in message
oups.com...
Obviously I'm a ultra newbie to this. I tried searching this
group and
find stuff that is close, but not what I need. If fear that I
am
looking for something that is so easy, that everyone else has
figured
it out. Hence, I cannot find the right solution.

See below for the oh so eloquent abortion of code that I have
brought
together.

Dim span As Range
Dim divisions As Range
Set span.Value = Worksheets("Sheet1").Range("G20")
Set divisions.Value = Worksheets("Sheet1").Range("E20")
Set answer.Value = span.Value / divisions.Value
Worksheets("Sheet1").Range("J20").Value = answer.Value

Now that I have the masses writhing in pain from my stupidity,
could
someone rectify the situation for this dolt.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Yes, I'm an idiot...But I cannot seem to divide two values in VBA see below

You need to Set the object (range) variable, not its value, to the
range. Also, your answer is a double, not an object. Here's one way:

Dim span As Range
Dim divisions As Range
Dim answer As Double
Set span = Worksheets("Sheet1").Range("G20")
Set divisions = Worksheets("Sheet1").Range("E20")
answer = span.value / divisions.Value
Worksheets("Sheet1").Range("J20").Value = answer

Another, using With...End With:

Dim span As Range
Dim divisions As Range
Dim answer As Double
With Worksheets("Sheet1")
Set span = .Range("G20")
Set divisions = .Range("E20")
answer = span.value / divisions.Value
.Range("J20").Value = answer
End With

You could avoid object variables altogether:

Dim answer As Double
Dim span As Double
Dim divisions As Double
span = Worksheets("Sheet1").Range("G20").Value
divisions = Worksheets("Sheet1").Range("E20").Value
answer = span / divisions
Worksheets("Sheet1").Range("J20").Value = answer

Alteratively, without using intermediate variables:

With Worksheets("Sheet1")
.Range("J20").Value = _
.Range("G20").Value / .Range("E20").Value
End With




In article .com,
wrote:

Obviously I'm a ultra newbie to this. I tried searching this group and
find stuff that is close, but not what I need. If fear that I am
looking for something that is so easy, that everyone else has figured
it out. Hence, I cannot find the right solution.

See below for the oh so eloquent abortion of code that I have brought
together.

Dim span As Range
Dim divisions As Range
Set span.Value = Worksheets("Sheet1").Range("G20")
Set divisions.Value = Worksheets("Sheet1").Range("E20")
Set answer.Value = span.Value / divisions.Value
Worksheets("Sheet1").Range("J20").Value = answer.Value

Now that I have the masses writhing in pain from my stupidity, could
someone rectify the situation for this dolt.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Yes, I'm an idiot...But I cannot seem to divide two values in VBA see below

In full disclosure I will post the entire code. I keep getting a
"Overflow error".
----------------------------------------------------------------------------------------------
Private Sub ComboBox1_Change()
If ComboBox1.Value = "" Then Exit Sub
If ComboBox1.Value = "µm per pixel" Then
Sheets("Sheet1").Range("N20").Value = _
Sheets("Sheet2").Range("B21").Value
With Worksheets("Sheet1")
.Range("J20").Value = _
.Range("G20").Value / .Range("E20").Value
End With
ElseIf ComboBox1.Value = "µm per div" Then
Sheets("Sheet1").Range("N20").Value = _
Sheets("Sheet2").Range("B21").Value
ElseIf ComboBox1.Value = "thou per pixel" Then
Sheets("Sheet1").Range("N20").Value = _
Sheets("Sheet2").Range("D21").Value
ElseIf ComboBox1.Value = "thou per div" Then
Sheets("Sheet1").Range("N20").Value = _
Sheets("Sheet2").Range("D21").Value
ElseIf ComboBox1.Value = "mag" Then
Sheets("Sheet1").Range("N20").Value = _
Sheets("Sheet2").Range("B143").Value
ElseIf ComboBox10.Value = "N/A" Then
Sheets("Sheet1").Range("N20").Value = "N/A"
Sheets("Sheet1").Range("J20").Value = "N/A"
End If
Application.ScreenUpdating = True
End Sub
-----------------------------------------------------------------------------------------------------

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Yes, I'm an idiot...But I cannot seem to divide two values in VBA see below

One more if you don't specifically need to create those range references.

With Worksheets("Sheet1")
.Range("J20").value = .Range("G20").Value/.Range("E20").Value
End With


--
Regards,
Tom Ogilvy


wrote in message
oups.com...
Obviously I'm a ultra newbie to this. I tried searching this group and
find stuff that is close, but not what I need. If fear that I am
looking for something that is so easy, that everyone else has figured
it out. Hence, I cannot find the right solution.

See below for the oh so eloquent abortion of code that I have brought
together.

Dim span As Range
Dim divisions As Range
Set span.Value = Worksheets("Sheet1").Range("G20")
Set divisions.Value = Worksheets("Sheet1").Range("E20")
Set answer.Value = span.Value / divisions.Value
Worksheets("Sheet1").Range("J20").Value = answer.Value

Now that I have the masses writhing in pain from my stupidity, could
someone rectify the situation for this dolt.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Yes, I'm an idiot...But I cannot seem to divide two values in VBA see below

Ok,

I figured out that I didn't have any numbers in those cells and it was
throwing a Overflow error.

Thanks to the both of you. I do appreciate it.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to divide all values with a fixed value ? fax Excel Discussion (Misc queries) 2 November 21st 05 07:12 PM
divide values by 10000 danielpaval New Users to Excel 2 October 6th 05 04:57 PM
dummy alert - divide values by values Micayla Bergen Excel Discussion (Misc queries) 1 May 4th 05 02:16 AM
How do you divide all values in the worksheet by 1000000 me Excel Worksheet Functions 1 April 25th 05 04:29 AM
Divide Expression stops in Macro when Can't divide JUAN Excel Programming 6 May 6th 04 07:05 AM


All times are GMT +1. The time now is 01:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"