Visual Basic In Excel

Get help on programming - C++, Java, Delphi, etc.
Post Reply
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Visual Basic In Excel

Post by DarkRanger »

Hi People!

I have to do a little programming in Excel. I'm struggeling with this code. I have completed all of it, but I cant seem to make it work.

I want it to calculate d in the following equation.

((W - 2 * x * (H - d)) * (L - 2 * x * (H - d)) + (W - 2 * H * x) * (L - 2 * H * x)) * 0.5 * d

I have done most of the code, the problem is it doesn't want to calculate a lot of values at once.

This is the code:

Code: Select all

Option Explicit
Dim W As Double
Dim x As Double
Dim H As Double
Dim L As Double
Dim V As Double
Dim d As Double
Dim A As Double

Private Sub CommandButton1_Click()

Dim c As Double
Dim x As Integer

c = 63
  W = Cells(17, 9).Value
  x = Cells(18, 9).Value
  H = Cells(18, 4).Value
  L = Cells(17, 4).Value
Range("E63").Select
Do Until IsEmpty(ActiveCell)
  d = 0
  V = ActiveCell.Value
  A = Round(((W - 2 * x * (H - d)) * (L - 2 * x * (H - d)) + (W - 2 * H * x) * (L - 2 * H * x)) * 0.5 * d, 1)
  V = Round(V, 1)
    If A <> V Then
      d = d + 0.00001
      'Cells(c, 6).Value = 0
      'Cells(c, 16).Value = 0
    Else
      Cells(c, 6).Value = d
      Cells(c, 16).Value = A
      c = c + 1
      If IsEmpty(ActiveSheet.Cells(c, 5)) Then
        Exit Sub
      Else
        d = 0
      End If  'If IsEmpty(ActiveSheet.Cells(c,5) Then
    End If 'If A <> V Then
  'If IsEmpty(ActiveCell) Then
   ' Exit Do
'  Else
  '  ActiveCell.Offset(1, 0).Select
 ' End If 'If IsEmpty
Loop 'Do Until...

End Sub
These are the variables:

W : Width
L : Length
x : is slope (i.e 1 : x )
H : Total depth of dam
d : depth of water at any given time

As you can derive, it has to calculate dimension etc. of a dam.

ANY HELP will be appreciated.

Thanks guys!
Image
SoulBlade
Registered User
Posts: 11025
Joined: 29 Sep 2003, 02:00
Location: /\/¯¯¯¯¯\/\
Contact:

Post by SoulBlade »

Just saw this now.
Give a screenshot of the values or send me the workbook.
Core i5 3550 | 8GB RAM | 500W | Samsung T260 | GTX760 OC | 4.56TB HDD space
GrimStoner
Registered User
Posts: 716
Joined: 08 Oct 2004, 02:00
Contact:

Post by GrimStoner »

Shouldn't there be a = in there somewhere if its an equation?
User avatar
Tribble
Registered User
Posts: 88465
Joined: 08 Feb 2007, 02:00
Processor: Intel Core i7-4770K CPU@3.50GHz
Motherboard: ACPI x64-based PC
Graphics card: GeForce GTX 780 Ti
Memory: 16GB
Location: Not here
Contact:

Post by Tribble »

Sorry, still learning VBA so will be no hope to you here. With what little knowledge I have, it looks fine. See I am clueless.
Image
SoulBlade
Registered User
Posts: 11025
Joined: 29 Sep 2003, 02:00
Location: /\/¯¯¯¯¯\/\
Contact:

Post by SoulBlade »

@ GrimStoner
A does recieve the value. Look at his code.
Core i5 3550 | 8GB RAM | 500W | Samsung T260 | GTX760 OC | 4.56TB HDD space
Post Reply