Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Loop through Columns

Hi,

I have a spreadsheet that is formatted the following way:

Jan Feb Mar Apr May
Jun
Actual Actual Actual Actual Forecast Forecast
6000 8000 6500 7500 8000
6000

I need to run a macro each month that loops thru the columes and
highlights the last Actual column and pastes formulas and formatting
into the first Forecast column. The number of columns change each month
as we forecast out further.

Any help would be greatly appreciated.

Thanks

Sally

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Loop through Columns

You can use the following VBA code to identify the next empty column, set
the value of xr to be the row where the data resides, you can loop this
value if there are many rows to test.

xr = 1
xNextEmptyCol = Cells(xr, Columns.Count).End(xlToLeft).Column + 1

then use the value to set the fomula into the column eg...

Cells(xr,xNextEmptyCol).Formula = "your formula"



--
Cheers
Nigel



"Sally" wrote in message
ups.com...
Hi,

I have a spreadsheet that is formatted the following way:

Jan Feb Mar Apr May
Jun
Actual Actual Actual Actual Forecast Forecast
6000 8000 6500 7500 8000
6000

I need to run a macro each month that loops thru the columes and
highlights the last Actual column and pastes formulas and formatting
into the first Forecast column. The number of columns change each month
as we forecast out further.

Any help would be greatly appreciated.

Thanks

Sally



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Loop through Columns

Thanks Nigel,

The cell actually has text in it though. I need to loop by column until
"Actual" changes to "Forecast"

Any ideas?

Thanks

Sally

Nigel wrote:
You can use the following VBA code to identify the next empty column, set
the value of xr to be the row where the data resides, you can loop this
value if there are many rows to test.

xr = 1
xNextEmptyCol = Cells(xr, Columns.Count).End(xlToLeft).Column + 1

then use the value to set the fomula into the column eg...

Cells(xr,xNextEmptyCol).Formula = "your formula"



--
Cheers
Nigel



"Sally" wrote in message
ups.com...
Hi,

I have a spreadsheet that is formatted the following way:

Jan Feb Mar Apr May
Jun
Actual Actual Actual Actual Forecast Forecast
6000 8000 6500 7500 8000
6000

I need to run a macro each month that loops thru the columes and
highlights the last Actual column and pastes formulas and formatting
into the first Forecast column. The number of columns change each month
as we forecast out further.

Any help would be greatly appreciated.

Thanks

Sally


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Loop through Columns

Hi Sally
Try this.....

Sub NextForecast()
Dim xc As Integer, xr As Long

xr = 1
For xc = 1 To 255
If Trim(UCase(Cells(xr, xc))) = "FORECAST" Then Exit For
Next xc

MsgBox "First Column with Forecast: " & xc

End Sub

xr refers to the row in which the headings appear. I show the result in a
message box but you can use this value in your formula


--
Cheers
Nigel



"Sally" wrote in message
oups.com...
Thanks Nigel,

The cell actually has text in it though. I need to loop by column until
"Actual" changes to "Forecast"

Any ideas?

Thanks

Sally

Nigel wrote:
You can use the following VBA code to identify the next empty column, set
the value of xr to be the row where the data resides, you can loop this
value if there are many rows to test.

xr = 1
xNextEmptyCol = Cells(xr, Columns.Count).End(xlToLeft).Column + 1

then use the value to set the fomula into the column eg...

Cells(xr,xNextEmptyCol).Formula = "your formula"



--
Cheers
Nigel



"Sally" wrote in message
ups.com...
Hi,

I have a spreadsheet that is formatted the following way:

Jan Feb Mar Apr May
Jun
Actual Actual Actual Actual Forecast Forecast
6000 8000 6500 7500 8000
6000

I need to run a macro each month that loops thru the columes and
highlights the last Actual column and pastes formulas and formatting
into the first Forecast column. The number of columns change each month
as we forecast out further.

Any help would be greatly appreciated.

Thanks

Sally




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop same formula for different columns? JD Excel Programming 0 February 3rd 06 02:20 AM
how to loop thru cell in 2 columns DMB Excel Programming 1 January 10th 06 03:51 PM
loop over columns kizzie Excel Discussion (Misc queries) 4 August 10th 05 01:31 PM
loop through columns hotherps[_78_] Excel Programming 6 July 23rd 04 11:40 AM
Loop 20 columns Help! Michael168[_106_] Excel Programming 2 July 2nd 04 12:26 PM


All times are GMT +1. The time now is 12:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"