Results 1 to 4 of 4

Range object/property problem.

Threaded View

mjsheen Range object/property problem. 06-01-2009, 10:02 PM
mjsheen Re: Range object/property... 06-01-2009, 11:11 PM
DonkeyOte Re: Range object/property... 06-02-2009, 03:14 AM
mjsheen Re: Range object/property... 06-02-2009, 03:21 AM
  1. #1
    Registered User
    Join Date
    06-01-2009
    Location
    Seoul
    MS-Off Ver
    Excel 2003
    Posts
    4

    Range object/property problem.

    Hail Experts!

    I'm trying to write a code that calculates 2nd column based on 3rd column's number or vice versa based on the condition set on the 1st column.

    Below, there are two procedures. "SimpleCalc" and "SimpleCalc2".
    I first wrote SimpleCalc2, but it isn't working, so I worked around the error by writing SimpleCalc, which selects a cell and moves around by offset. I personally find it hard to read and error prone as I develop more logic around it.

    I'm trying to develop more function based on this code, so I need to make it neat and flexible.

    Can anyone tell me what I'm doing wrong in SimpleCalc2? Or do you have any suggestion to improve the code "SimpleCalc"?

    I'm using Excel 2003.

    Thanks!

    ---------------------

    Sub SimpleCalc()

    Dim SimpleMethodRng, SimpleMethod As String, i As Integer

    ActiveWorkbook.Worksheets("Dashboard").Range("P5").Select

    SimpleMethodRng = ActiveWorkbook.Worksheets("Dashboard").Range("N5:P12")

    For i = 1 To 8

    SimpleMethod = SimpleMethodRng(i, 1)

    If SimpleMethod = "per pyung" Then _
    Selection.Offset(i - 1, 0).Value = SimpleMethodRng(i, 2) * Range("GLA") _
    Else Selection.Offset(i - 1, -1).Value = SimpleMethodRng(i, 3) / Range("GLA")

    Next i

    End Sub


    Sub SimpleCalc2()

    Dim SimpleMethodRng As Range, SimpleMethod As String, i As Integer

    SimpleMethodRng = ActiveWorkbook.Worksheets("Dashboard").Range("N5:P12")

    For i = 1 To 8

    If SimpleMethodRng(i, 1) = "per pyung" Then _
    SimpleMethodRng(i, 3).Value = SimpleMethodRng(i, 2) * Range("GLA") _
    Else SimpleMethodRng(i, 2).Value = SimpleMethodRng(i, 3) / Range("GLA")

    Next i

    End Sub
    Last edited by mjsheen; 06-02-2009 at 03:28 AM. Reason: solved

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1