+ Reply to Thread
Results 1 to 4 of 4

Macros question

  1. #1
    Registered User
    Join Date
    06-20-2006
    Posts
    15

    Macros question

    Hi all,

    I need some help editing code for my macro. I want to bold all lines that have the word Total in them. There are 2 problems I'm running into:

    1) I read the macro script - all cell addresses are hard codes . How can I have the script just go to the next line instead of a hard-coded cell number.

    2) How can I make the macro run over an over again until it reaches end of line?

    Thanks a ton!

  2. #2
    Jim Thomlinson
    Guest

    RE: Macros question

    Here is some code. To make it more efficient it uses find instead of
    searching each cell one at a time... You will need to change some things to
    suit.

    Public Sub boldRows()
    Dim rngFound As Range
    Dim rngToSearch As Range
    Dim rngFoundAll As Range
    Dim wks As Worksheet
    Dim strFirst As String

    Set wks = Sheets("Sheet3") 'Change thins
    Set rngToSearch = wks.Range("A:A") 'Change This
    Set rngFound = rngToSearch.Find(What:="Total", _
    LookIn:=xlFormulas, _
    LookAt:=xlPart, _
    MatchCase:=False)
    If rngFound Is Nothing Then
    MsgBox "Couldn't Find Total"
    Else
    strFirst = rngFound.Address
    Set rngFoundAll = rngFound
    Do
    Set rngFoundAll = Union(rngFound, rngFoundAll)
    Set rngFound = rngToSearch.FindNext(rngFound)
    Loop Until rngFound.Address = strFirst
    rngFoundAll.EntireRow.Font.Bold = True
    End If
    End Sub

    --
    HTH...

    Jim Thomlinson


    "cooldyood" wrote:

    >
    > Hi all,
    >
    > I need some help editing code for my macro. I want to bold all lines
    > that have the word Total in them. There are 2 problems I'm running
    > into:
    >
    > 1) I read the macro script - all cell addresses are hard codes . How
    > can I have the script just go to the next line instead of a hard-coded
    > cell number.
    >
    > 2) How can I make the macro run over an over again until it reaches end
    > of line?
    >
    > Thanks a ton!
    >
    >
    > --
    > cooldyood
    > ------------------------------------------------------------------------
    > cooldyood's Profile: http://www.excelforum.com/member.php...o&userid=35611
    > View this thread: http://www.excelforum.com/showthread...hreadid=553827
    >
    >


  3. #3
    Registered User
    Join Date
    06-20-2006
    Posts
    15
    It worked, thank you. I just have a quick question. I'd like to run the macro for the current sheet instead of hard-coding the sheet name. What do I need to change in this line?

    Set wks = Sheets("May 06")

    Thx again.

  4. #4
    Registered User
    Join Date
    06-20-2006
    Posts
    15
    Can anyone tell me??

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1