ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   macros (https://www.excelbanter.com/excel-worksheet-functions/199518-macros.html)

scott

macros
 
is it possible to create a macro that can take into account the number of
columns containing data? in a workbook i have a tab for each month of the
year for 2001-2008, and because each month has varying numbers of days in it,
the number of iterations i need to do differs, and the number of columns for
iterations changes back and forth from 6 to 7. im just looking for a
time-saving method instead of manually including or removing the number of
columns to consider.

thanks in advance.

Rick Rothstein \(MVP - VB\)[_1146_]

macros
 
It is hard to determine it this will work for you given the sketchy
description of your column layout, but this statement will return the last
column number containing data...

Worksheets("Sheet1").Cells(RowNum, Columns.Count).End(xlToLeft).Column

Just assign it to a variable, use it in an If..Then logical expression or
whatever. The RowNum variable in the Cells property call is the row number
to examine... you can use your own variable name, or hard code the row's
number, there instead.

Rick


"scott" wrote in message
...
is it possible to create a macro that can take into account the number of
columns containing data? in a workbook i have a tab for each month of the
year for 2001-2008, and because each month has varying numbers of days in
it,
the number of iterations i need to do differs, and the number of columns
for
iterations changes back and forth from 6 to 7. im just looking for a
time-saving method instead of manually including or removing the number of
columns to consider.

thanks in advance.



scott

macros
 
sorry for the sketchy description, hopefully this is better.

in each worksheet i have the data in column b for each day of a month that
is in column a. column c is the sorted data that is contained in column b.
column d contains the average of every 5 data points in column c; starting in
d5, the average of c1:c5 is calculated...d6 contains the average of c2:c6, d7
contains the average of c3:c7, etc. column e has the aveages of column d
starting at d10, column f starting at f15, etc. because each month has
either 30 or 31 days (february has 28 of course), the number of columns that
i will peform iterations in will differ..can i write a macro on one sheet
that i can use for each sheet in the workbook that takes into account the
number of columns each worksheet has?

"scott" wrote:

is it possible to create a macro that can take into account the number of
columns containing data? in a workbook i have a tab for each month of the
year for 2001-2008, and because each month has varying numbers of days in it,
the number of iterations i need to do differs, and the number of columns for
iterations changes back and forth from 6 to 7. im just looking for a
time-saving method instead of manually including or removing the number of
columns to consider.

thanks in advance.



All times are GMT +1. The time now is 06:45 PM.

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