PC Review


Reply
Thread Tools Rate Thread

Code in Excel - adjust for Access

 
 
=?Utf-8?B?ZGR1bmtz?=
Guest
Posts: n/a
 
      27th Jun 2006
This is our rubberband macro(actually two macros here; one is called FindNext
and is called from the first macro) . We use it in Excel to against the
“tool” data. It “starts” at IAP_Benchmark of 0, and does the code, generating
the factors you see here.
I have played around trying to get this code to work against the same data
Iin an Access database. Any suggestions?

Log_Dist IAP_Benchmark Factor
-15.91
-2.62
-1.40
0.00 0 1.075
1.40
4.39
6.51 7 0.987
8.01
19.68 20 1.012
28.92
36.99
38.46 39 1




On Error GoTo err_Handler

Dim currentBenchmark As Long
Dim newBenchmark As Long
Dim currentFootage As Double
Dim newFootage As Double
Dim deltaBenchmark As Double
Dim deltaFootage As Double
Dim newFactor As Double
Dim factorCell

currentBenchmark = ActiveCell.Value
currentFootage = ActiveCell.Offset(0, -1).Value

Do
'Get new factor cell
factorCell = ActiveCell.Offset(0, 1).Address
ActiveCell.Offset(1).Activate
FindNext
newBenchmark = ActiveCell.Value
newFootage = ActiveCell.Offset(0, -1).Value

deltaBenchmark = newBenchmark - currentBenchmark
deltaFootage = newFootage - currentFootage
If deltaFootage > 0 Then
newFactor = deltaBenchmark / deltaFootage
Else
Range(factorCell).Value = 1
Exit Sub
End If

' Place factor in factor cell
Range(factorCell).Value = newFactor

currentBenchmark = newBenchmark
currentFootage = newFootage

Loop Until ActiveCell.Offset(1, -1).Value = 0

ActivateCell.Offset(0, 1).Value = 1


err_exit:
Exit Sub
err_Handler:
MsgBox Err.Number & " - " & Err.Description
Resume err_exit

End Sub


Sub FindNext()

Do While ActiveCell.Offset(0, -1).Value > 0 And ActiveCell.Value = 0
ActiveCell.Offset(1).Select
Loop

End Sub

 
Reply With Quote
 
 
 
 
Douglas J Steele
Guest
Posts: n/a
 
      27th Jun 2006
While the interface may look similar, Access and Excel are very different
products. Techniques such as what you're using in Excel that rely on
"previous row" don't translate into Access.

Perhaps you can explain what it is you're trying to do in words, and someone
can help you achieve that functionality in Access.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"ddunks" <(E-Mail Removed)> wrote in message
news:EEA32F6A-63D7-4ABF-9EC5-(E-Mail Removed)...
> This is our rubberband macro(actually two macros here; one is called

FindNext
> and is called from the first macro) . We use it in Excel to against the
> "tool" data. It "starts" at IAP_Benchmark of 0, and does the code,

generating
> the factors you see here.
> I have played around trying to get this code to work against the same data
> Iin an Access database. Any suggestions?
>
> Log_Dist IAP_Benchmark Factor
> -15.91
> -2.62
> -1.40
> 0.00 0 1.075
> 1.40
> 4.39
> 6.51 7 0.987
> 8.01
> 19.68 20 1.012
> 28.92
> 36.99
> 38.46 39 1
>
>
>
>
> On Error GoTo err_Handler
>
> Dim currentBenchmark As Long
> Dim newBenchmark As Long
> Dim currentFootage As Double
> Dim newFootage As Double
> Dim deltaBenchmark As Double
> Dim deltaFootage As Double
> Dim newFactor As Double
> Dim factorCell
>
> currentBenchmark = ActiveCell.Value
> currentFootage = ActiveCell.Offset(0, -1).Value
>
> Do
> 'Get new factor cell
> factorCell = ActiveCell.Offset(0, 1).Address
> ActiveCell.Offset(1).Activate
> FindNext
> newBenchmark = ActiveCell.Value
> newFootage = ActiveCell.Offset(0, -1).Value
>
> deltaBenchmark = newBenchmark - currentBenchmark
> deltaFootage = newFootage - currentFootage
> If deltaFootage > 0 Then
> newFactor = deltaBenchmark / deltaFootage
> Else
> Range(factorCell).Value = 1
> Exit Sub
> End If
>
> ' Place factor in factor cell
> Range(factorCell).Value = newFactor
>
> currentBenchmark = newBenchmark
> currentFootage = newFootage
>
> Loop Until ActiveCell.Offset(1, -1).Value = 0
>
> ActivateCell.Offset(0, 1).Value = 1
>
>
> err_exit:
> Exit Sub
> err_Handler:
> MsgBox Err.Number & " - " & Err.Description
> Resume err_exit
>
> End Sub
>
>
> Sub FindNext()
>
> Do While ActiveCell.Offset(0, -1).Value > 0 And ActiveCell.Value = 0
> ActiveCell.Offset(1).Select
> Loop
>
> End Sub
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
help to adjust my code =?Utf-8?B?QW50aG9ueQ==?= Microsoft Excel Programming 2 14th Mar 2007 09:20 PM
Help to adjust code =?Utf-8?B?U2lvdXhpZVE=?= Microsoft Excel Programming 0 27th Nov 2004 07:45 PM
HELP - I need to adjust code!!!! jriendeau5 Microsoft Excel Programming 1 5th Nov 2004 02:29 AM
HELP - I need to adjust code!!!! jriendeau5 Microsoft Excel Programming 1 4th Nov 2004 08:26 PM
Adjust code access security rights programmaticly or through script? JDeats Microsoft C# .NET 1 24th Oct 2003 10:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:59 PM.