LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Storing variables in a macro and using those variables to performcalculations.

Hello Experts,

I am brand new to VBA, and am having a few problems writing a macro.
I would like to have the macro search through my data and find the
PT1, PT2, and 2. Whenever one of these is found, I'd like some data
from the same row to be stored as a variable. Once a variable for 2
is stored, I'd like it to perform a series of calculations and display
the results. I'm using select case because the data is not in any
predictable order. My code is below:

Static Sub IterativeCalc()

' Keyboard Shortcut: Ctrl+Shift+I

Dim EbiPT1, EbiPT2, EbiQC2, MC, MpH As Double

I2 = Range("$I$2").Value
E3 = Range("$E$3").Value
I3 = Range("$I$3").Value
F3 = Range("$F$3").Value
E2 = Range("$E$2").Value


Dim cell As Range
For Each cell In Range(ActiveCell, ActiveCell.End(xlDown))
With cell

' First, for PT1, PT2, and 2. The Calculations will be performed
once the macro finds 2.

Select Case .Text

Case "PT1"
ActiveCell.Offset(0, 2).Value = EbiPT1
ActiveCell.Offset(1, 0).Activate

Case "PT2"
ActiveCell.Offset(0, 2).Value = EbiPT2
ActiveCell.Offset(1, 0).Activate

Case "2"
ActiveCell.Offset(0, 2).Value = EbiQC2
ActiveCell.Offset(1, 0).Activate


'Now we will perform the calculations

ActiveCell.Offset(0, 7).Value = (EbiQC2 - EbiPT2) /
(Log((I3 / 1000) / (F3 / 1000)) / Log(10#))
ActiveCell.Offest(0, 7).Value = MC
ActiveCell.Offset(1, 7).Value = (EbiQC2 - EbiPT1) / (I2 -
E2)
ActiveCell.Offset(1, 7).Value = MpH
ActiveCell.Offset(2, 7).Value = EbiPT2 - MC * (Log(F3 /
1000) / Log(10#))
ActiveCell.Offset(3, 7).Value = EbiPT1 - MpH * E2


End Select

End With
Next cell

End Sub

It seems like the macro is scanning through my data, but I can't get
it to do the calculations. I've also written custom functions to
perform the calculations, but when I use these, it still doesn't
work.

Any help is greatly appreciated.

Thanks!

Greg
 
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
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Using variables while running macro TheLeafs[_4_] Excel Programming 2 February 28th 06 02:47 PM
Excel-VB Macro Variables Eunice W Excel Programming 2 December 18th 05 04:22 PM
Storing and Retrieving Variables Question JasonSelf Excel Programming 2 January 23rd 04 03:12 PM
Storing Variables Todd Huttenstine[_3_] Excel Programming 5 November 27th 03 02:14 AM


All times are GMT +1. The time now is 03:00 AM.

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

About Us

"It's about Microsoft Excel"