ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   writting data in the next available column (https://www.excelbanter.com/excel-programming/349950-writting-data-next-available-column.html)

voodooJoe

writting data in the next available column
 
there are many ways to do this, btu all are generally variations on 2
themes:

a) using .end(xlright) - basically going to the far end of the spreadsheet
and then going back to the left to find the last cell with something in it
b) look for cells with data and go to the next column - presumabley blank.

both ways have pluses and minuses. i prefer B as it doesn't rely on cells
outside your table always being blank

my favorite way is to use a self-resetting named range. to do this you use
a named range in the workbook that resets itself each time a new column of
data is added to the table.
this works wether you do it manually or by macro.

Sub y()

ThisWorkbook.Names.Add Name:="Banana",
RefersTo:="=OFFSET(Sheet1!$A$2,0,COUNTA(Sheet1!$2: $2),10,1)"
Set rng = Range("Banana")

rng.Select
For i = 1 To 10
rng.Cells(i, 1) = i
Next i

End Sub

an alternative - if you don't want to use a named range is to use the
..currentregion method

Set rng = Sheet1.Cells(1, 1).CurrentRegion.Offset(0, 1).Resize(rowsize:=10)

- voodooJoe


"yorke" wrote in message
oups.com...
hello,

i'm creating a weekly reporting and have my weeks (1-52) lined up from
column D (week 1) to ...
Each week I want my VbA macro to add data to the next availabel (=
blank) column,
i already created a form with all the data (labels) that have to go in
the right column.
Your response in english or Nederlands !!

thx




yorke

writting data in the next available column
 
hello,

i'm creating a weekly reporting and have my weeks (1-52) lined up from
column D (week 1) to ...
Each week I want my VbA macro to add data to the next availabel (=
blank) column,
i already created a form with all the data (labels) that have to go in
the right column.
Your response in english or Nederlands !!

thx



All times are GMT +1. The time now is 11:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com