Consulting

Results 1 to 6 of 6

Thread: Solved: filling in data, relative to the active cell

  1. #1

    Solved: filling in data, relative to the active cell

    hi,

    i'm a virgin VBA coder tackling my first nubile little program. i want to input, say:

    100 200 300 400 500

    but instead of inputting it into a specific range, like A1:E1, i want to be able to designate the first cell. so when i run the macro, it will fill in the numbers to the right of whatever the active cell is. any help is greatly appreciated! thanks!

  2. #2
    Site Admin VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    ActiveCell.OffSet(0,1)

    the first value is for Rows and the second is for columns.

    Regards,
    SImon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Hi Alchemist,

    Welcome to VBAX!!

    Just to expand on what has already posted

    [VBA]Sub FillItIn()
    ActiveCell.Offset(0, 1).Value = "100"
    ActiveCell.Offset(0, 2).Value = "200"
    ActiveCell.Offset(0, 3).Value = "300"
    ActiveCell.Offset(0, 4).Value = "400"
    ActiveCell.Offset(0, 5).Value = "500"
    End Sub[/VBA]

  4. #4
    thanks guys! it's truly beautiful to see a piece of code work.

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Alchemist,
    Welcome to VBAX
    It won't be long before you come across Arrays, so here's a gentle introduction to answer your question.

    [vba]Option Explicit

    Sub Test1()
    Dim Arr, i As Long
    Arr = Array(100, 200, 300, 400, 500)
    For i = 0 To UBound(Arr)
    ActiveCell.Offset(0, 1 + i) = Arr(i)
    Next
    End Sub

    Sub Test2()
    Dim Arr, i As Long
    Arr = Array(100, 200, 300, 400, 500)
    ActiveCell.Offset(0, 1).Resize(1, UBound(Arr) + 1) = Arr
    End Sub
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    thank you for being so gentle. i will play around with these arrays.

Posting Permissions

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