Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default VBA to Search, Insert Column and Sum

I have an Excel app that generates the dates for the month using NETWORKDAYS
across the top row. What I'm struggling with now is how to loop through all
the columns searching for "FRIDAY" and inserting a blank column to sum the
weeks numbers. Any help would be greatly appreciated. Thx
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VBA to Search, Insert Column and Sum

Do the cells in row 1 contain dates--or the actual text Friday. I don't mean
how the values are formatted. I mean what's really in the cell?

I'm guessing that it's a date:

Option Explicit
Sub testme()
Dim iCol As Long
Dim wks As Worksheet

Set wks = Worksheets("Sheet1")

With wks
For iCol = 1 To .Cells(1, .Columns.Count).End(xlToLeft).Column
If Weekday(.Cells(1, iCol).Value) = vbFriday Then
.Columns(iCol + 1).Insert
End If
Next iCol
End With
End Sub

Richard wrote:

I have an Excel app that generates the dates for the month using NETWORKDAYS
across the top row. What I'm struggling with now is how to loop through all
the columns searching for "FRIDAY" and inserting a blank column to sum the
weeks numbers. Any help would be greatly appreciated. Thx


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default VBA to Search, Insert Column and Sum

Hi Richard,

a small suggestion since you are adding columns -- use what Dave gave
you but loop from the last to the first...

For iCol = .Cells(1, .Columns.Count).End(xlToLeft).Column to 1 Step -1


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*



Dave Peterson wrote:
Do the cells in row 1 contain dates--or the actual text Friday. I don't mean
how the values are formatted. I mean what's really in the cell?

I'm guessing that it's a date:

Option Explicit
Sub testme()
Dim iCol As Long
Dim wks As Worksheet

Set wks = Worksheets("Sheet1")

With wks
For iCol = 1 To .Cells(1, .Columns.Count).End(xlToLeft).Column
If Weekday(.Cells(1, iCol).Value) = vbFriday Then
.Columns(iCol + 1).Insert
End If
Next iCol
End With
End Sub

Richard wrote:
I have an Excel app that generates the dates for the month using NETWORKDAYS
across the top row. What I'm struggling with now is how to loop through all
the columns searching for "FRIDAY" and inserting a blank column to sum the
weeks numbers. Any help would be greatly appreciated. Thx


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VBA to Search, Insert Column and Sum

Thanks for the correction.

I intended to do just that, but screwed up!

strive4peace wrote:

Hi Richard,

a small suggestion since you are adding columns -- use what Dave gave
you but loop from the last to the first...

For iCol = .Cells(1, .Columns.Count).End(xlToLeft).Column to 1 Step -1

Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*

Dave Peterson wrote:
Do the cells in row 1 contain dates--or the actual text Friday. I don't mean
how the values are formatted. I mean what's really in the cell?

I'm guessing that it's a date:

Option Explicit
Sub testme()
Dim iCol As Long
Dim wks As Worksheet

Set wks = Worksheets("Sheet1")

With wks
For iCol = 1 To .Cells(1, .Columns.Count).End(xlToLeft).Column
If Weekday(.Cells(1, iCol).Value) = vbFriday Then
.Columns(iCol + 1).Insert
End If
Next iCol
End With
End Sub

Richard wrote:
I have an Excel app that generates the dates for the month using NETWORKDAYS
across the top row. What I'm struggling with now is how to loop through all
the columns searching for "FRIDAY" and inserting a blank column to sum the
weeks numbers. Any help would be greatly appreciated. Thx



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default VBA to Search, Insert Column and Sum

you're welcome, Dave ;)


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*



Dave Peterson wrote:
Thanks for the correction.

I intended to do just that, but screwed up!

strive4peace wrote:
Hi Richard,

a small suggestion since you are adding columns -- use what Dave gave
you but loop from the last to the first...

For iCol = .Cells(1, .Columns.Count).End(xlToLeft).Column to 1 Step -1

Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*

Dave Peterson wrote:
Do the cells in row 1 contain dates--or the actual text Friday. I don't mean
how the values are formatted. I mean what's really in the cell?

I'm guessing that it's a date:

Option Explicit
Sub testme()
Dim iCol As Long
Dim wks As Worksheet

Set wks = Worksheets("Sheet1")

With wks
For iCol = 1 To .Cells(1, .Columns.Count).End(xlToLeft).Column
If Weekday(.Cells(1, iCol).Value) = vbFriday Then
.Columns(iCol + 1).Insert
End If
Next iCol
End With
End Sub

Richard wrote:
I have an Excel app that generates the dates for the month using NETWORKDAYS
across the top row. What I'm struggling with now is how to loop through all
the columns searching for "FRIDAY" and inserting a blank column to sum the
weeks numbers. Any help would be greatly appreciated. Thx


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
Search for a column based on the column header and then past data from it to another column in another workbook minkokiss Excel Programming 2 April 5th 07 01:12 AM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Programming 2 December 30th 06 06:23 PM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Discussion (Misc queries) 1 December 27th 06 05:47 PM
search for worksheet, insert new if doesn't exist cereldine[_19_] Excel Programming 2 April 21st 06 05:10 PM
Cell Text Search & Insert Value in Next Column Shaun[_6_] Excel Programming 3 February 28th 06 02:50 PM


All times are GMT +1. The time now is 03:50 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"