Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2007, 10:05 AM
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Looping through rows

Hi,

I'm sorry if this is a very basic question, but I am just getting to grips with writing my own macros in Excel.

I want the macro to run through column b and if column b = "Divn Totals" to then make everything on that row from column b to column ae bold and shaded in light grey.

The code I have done does this, but only for row 7.

Range("b7:ae7").Select

If [b7] = "Divn Totals" Then
Selection.Font.Bold = True
  With Selection.Interior
    .ColorIndex = 15
        .Pattern = xlSolid
   End With
  End If

Any ideas how I can do this for each row in the spreadsheet? Any help would be much appreciated!

Thanks
Amy



 
Old April 17th, 2007, 12:14 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Here you have Amy

Sub BoldFace_Matching_Text()

Dim r1 As Range

Set r1 = Range("b7:ae7")

For Each c1 In r1

    If c1 = "Divn Totals" Then
    c1.Font.Bold = True
      With c1.Interior
        .ColorIndex = 15
            .Pattern = xlSolid
       End With
    End If

Next c1
End Sub


I have used the range

Cheers
Shasur



http://www.vbadud.blogspot.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping ssaranam SQL Server 2005 2 April 17th, 2008 01:40 AM
looping mrjoka Classic ASP Basics 1 September 26th, 2007 12:21 AM
Looping deepsea007 XSLT 1 June 14th, 2007 12:13 PM
Looping..? dedex C# 2 January 6th, 2005 11:24 PM
Limit rows returned and next rows minhpx General .NET 1 August 12th, 2004 06:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.