View Full Version : Solved: filling in data, relative to the active cell
Alchemist
02-27-2007, 02:26 PM
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!
Simon Lloyd
02-27-2007, 03:07 PM
ActiveCell.OffSet(0,1)
the first value is for Rows and the second is for columns.
Regards,
SImon
Tommy
02-27-2007, 03:15 PM
Hi Alchemist, :hi:
Welcome to VBAX!!
Just to expand on what has already posted
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
Alchemist
02-27-2007, 03:37 PM
thanks guys! it's truly beautiful to see a piece of code work.
mdmackillop
02-27-2007, 04:34 PM
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.
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
Alchemist
02-27-2007, 04:55 PM
thank you for being so gentle. i will play around with these arrays.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.