Results 1 to 4 of 4

help to create loop in a defined range

Threaded View

  1. #1
    Registered User
    Join Date
    12-10-2009
    Location
    Baku
    MS-Off Ver
    Excel 2007
    Posts
    10

    help to create loop in a defined range

    hi all
    i am newbie in Excel VBA
    i created list in Excel and i wrote into (a1 cell-income, b1 cell-expence, c1 cell-kredit and d1 cell-debet)
    i enter a2 cell income (for ex:1000) and b2 cell expence (for ex: 100)
    and I give condition in VBA that if income greater than expence then VBA writes a2.value-b2.value into d2 cell
    else if expence greater than income then it writes b2.value-a2.value into c2 cell
    but i only define this one row (for ex: c2, a2. b2. d2)
    i would like to assign it the rows as long as i want
    that is i would like to create loop
    (for ex: a(i), b(i) and so on

    here is code

    pls help me i very need this code
    thanks beforehands
    Sub initialize()Dim i As IntegerDim lastrow As Long If (Range("b2").Value > Range("a2").Value) Then Range("c2").Value = Range("b2").Value - Range("a2").Value Range("d2").Value = "" Else Range("d2").Value = Range("a2").Value - Range("b2").Value Range("c2").Value = "" End If End SubSub initialize()
    Dim i As Integer
    Dim lastrow As Long
    
    If (Range("b2").Value > Range("a2").Value) Then
     Range("c2").Value = Range("b2").Value - Range("a2").Value
     Range("d2").Value = ""
     Else
     Range("d2").Value = Range("a2").Value - Range("b2").Value
     Range("c2").Value = ""
    
    End If
    
    End Sub
    Attached Files Attached Files
    Last edited by azegurb; 12-10-2009 at 03:31 AM.

Thread Information

Users Browsing this Thread

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

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