Excel VBA formula
Manage your personal finances in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Excel VBA formula

  1. #1
    New Member
    Join Date
    Apr 2002
    Posts
    23
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    I am just learning VBA for excel. I have a formula that I am having repeat numerous times. In this formula I am subtracting 2 cells. How do I preserve the formula while allowing it to change to the next row? If you look below, I am asking how to change "b5-C5" to "b6-C6" and so on as the code repeats.

    Selection.Offset(0, 2).Formula = "=B5-C5"


    Thanks!

  2. #2
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Use something like:


    Selection.AutoFill Destination:=Range("A1:A14"), Type:=xlFillDefault


    Where "A1:A14" is your target range and "A1" is the selected cell to copy from.

    HTH

  3. #3
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Do you want something like this:

    For i = 5 To 6
    Selection.Offset(i - 5, 2).Formula = "=" & Cells(i, 2).Address(rowabsolute:=False, columnabsolute:=False) _
    & "-" & Cells(i, 3).Address(rowabsolute:=False, columnabsolute:=False)
    Next i

    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  4. #4
    New Member
    Join Date
    Apr 2002
    Location
    Chile
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    I have the same problem, but it is in a search of a range I specify (a2:a10) and that it looks (search) for the content of a cell specifies (b2) and it replaces by the content of a cell specifies (c2).
    ¿How I make to change the values of the cells (b2, c2) to (b3, c3) to (b4,c4)etc ?
    please help
    thanks
    Pedro

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com