+ Reply to Thread
Results 1 to 11 of 11

Improving my format-macro

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-12-2006
    Posts
    106

    Improving my format-macro

    A friend wrote me this kind of macro that allows me to bold every other line after asking how many rows I want to go thru. I would like to get this improved. Or whole new macro, doesn't matter.

    1) Is there a way to automatize this macro to check what is the final row with entered data? So that empty rows at the end (not in middle of the sheet!) would be skipped.

    2) Is there a way to improve the "auto-check" so that it would do that for every sheet on that book? There are different amount of rows in sheets, maybe just checking the maximum amount of rows in a sheet would help on it? It just takes minutes to go theu whole 65536 rows, but I have like under 2000 rows per sheet at maximum. So making a macro that goes thru first 2000 rows in every sheet would be one solution.

    3) How could I add that kind of command that font thru whole sheet (or rather whole book) would be changed to Courier. So basically something like "select whole book - set font to courier". I like to work with Arial, but Courier is better when publishing and viewing with Firefox.

    4) How to add that kind of command that the whole book gets grid between cells? The grid I want is "all the borders/lines". So basically something like "select whole book - set all lines/borders on". I like to work without borders/lines, but it looks better to have those lines when publishing and viewing with Firefox.

    The macro I have now

    Sub Lihavoi()
    Rivit = CInt(InputBox("No, montaks rivii laitetaan"))
    JT = False
    For Each Rivi In Rows
    If R < Rivit Then
    If JT = False Then
    Rivi.Select
    Selection.Font.Bold = True
    JT = True
    Else
    JT = False
    End If
    R = R + 1
    Else
    Exit For
    End If
    Next
    End Sub

    Some quick Finnish for you to help (having that improved code in English is absolutely more than ok, but just to help you to understand the current solution I have)
    lihavoi = bold
    rivit = rows
    No, montaks rivii laitetaan = Well, how many rows do you want
    rivi = a row

  2. #2
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267
    Assuming your data is in ColumnA of every sheet in Workbook:

    Sub BoldFontsAlternately()
    Dim x as long, c as Range, sh as WorkSheet

    For each sh in WorkSheets
    Set rng = sh.Range(sh.Range("a1"), sh.Cells(rows.count,"A").End(xlUp))
    For each c in rng
    x=x+1
    If Mod(x,2) Then
    With c
    .Font.bold=True
    .Font.Name = "Courier"
    End with
    End If
    Next
    Next

    End Sub
    Last edited by Myles; 10-13-2006 at 11:24 PM.
    HTH
    Myles

    ...constantly looking for the smoother pebble while the whole ocean of truth lies before me.

  3. #3
    Forum Contributor
    Join Date
    08-12-2006
    Posts
    106
    Quote Originally Posted by Myles
    Assuming your data is in ColumnA of every sheet in Workbook:
    My data can actually be in over 100 columns per book.

    Does that courier now apply to each line? I mean, every line should be with courier and every other line should be also bolded. Yes, it is easy to just activate whole sheet and put courier and "grid" on, but I still would like it to be automatized.

    It also gives an error on "If Mod(x,2) Then"

    By the way, I am using Excel 2003 if that affects on anything.
    Last edited by Jaymond Flurrie; 10-14-2006 at 04:33 AM.

  4. #4
    Forum Contributor
    Join Date
    08-12-2006
    Posts
    106
    I tried this in English Excel too, doesn't work, gives the error in line

    If Mod(x,2) Then

  5. #5
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267
    My apologies. Use:

    Sub mnk()


    For Each sh In Worksheets
    Set rng = sh.Range(sh.Range("a1"), sh.Cells(Rows.Count, "A").End(xlUp))
    For Each c In rng
    x = x + 1
    If x Mod 2 Then
    With c
    .Font.Bold = True
    .Font.Name = "Courier"
    End With
    Else
    c.Font.Name = "Courier"
    End If
    Next
    Next

    End Sub

  6. #6
    Forum Contributor
    Join Date
    08-12-2006
    Posts
    106
    Quote Originally Posted by Myles
    My apologies. Use:

    Sub mnk()


    For Each sh In Worksheets
    Set rng = sh.Range(sh.Range("a1"), sh.Cells(Rows.Count, "A").End(xlUp))
    For Each c In rng
    x = x + 1
    If x Mod 2 Then
    With c
    .Font.Bold = True
    .Font.Name = "Courier"
    End With
    Else
    c.Font.Name = "Courier"
    End If
    Next
    Next

    End Sub
    Now it works, thank you. Any idea how to add that full grid there?

+ 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