Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Pank
 
Posts: n/a
Default Where am I going wrong?

I have the following macro, which works fine except for the two lines of code
before the With.PageSetup.

Only the last row in the last worksheet in the workbook is set to bold. All
other sheets have the description TOTAL NUMBER OF SKIPS set in the last row
in Col A and a corresponding count in the last row in column b, but it is not
bolded.

Any suggestions or ideas would be appreciated.


Sub Format()
Dim wks As Worksheet
Dim lLastRow As Long
Application.ScreenUpdating = False

If ActiveSheet.Name < "MAIN" Then

For Each wks In ActiveWorkbook.Worksheets
With wks

lLastRow = wks.Range("A1").End(xlDown).Row
wks.Cells(lLastRow + 1, 1).Formula = "TOTAL NUMBER OF SKIPS"
wks.Cells(lLastRow + 1, 2).Formula = "=COUNTROWS(B:B) - 2"
lLastRow = wks.Range("A1").End(xlDown).Row
wks.PageSetup.PrintArea = "$A$1:$K$" & lLastRow
lLastRow = wks.Range("A1").End(xlDown).Row
Rows(lLastRow).Select
Selection.Font.Bold = True

With .PageSetup

Page set up code

End With
.UsedRange.Rows.AutoFit
End With
Next wks
End If

More code down here.

  #2   Report Post  
Jim Rech
 
Posts: n/a
Default

Replace the last two lines with this:

wks.Rows(lLastRow).Font.Bold = True

This will set the font of the last row of each sheet bold (I assume that
what you want).

No selecting is necessary (selecting will not even work anyway since you are
not activating each worksheet.

Also, no need to repeat:

lLastRow = wks.Range("A1").End(xlDown).Row

Once is enough. Also you start With wks and never use it.

--
Jim
"Pank" wrote in message
...
|I have the following macro, which works fine except for the two lines of
code
| before the With.PageSetup.
|
| Only the last row in the last worksheet in the workbook is set to bold.
All
| other sheets have the description TOTAL NUMBER OF SKIPS set in the last
row
| in Col A and a corresponding count in the last row in column b, but it is
not
| bolded.
|
| Any suggestions or ideas would be appreciated.
|
|
| Sub Format()
| Dim wks As Worksheet
| Dim lLastRow As Long
| Application.ScreenUpdating = False
|
| If ActiveSheet.Name < "MAIN" Then
|
| For Each wks In ActiveWorkbook.Worksheets
| With wks
|
| lLastRow = wks.Range("A1").End(xlDown).Row
| wks.Cells(lLastRow + 1, 1).Formula = "TOTAL NUMBER OF SKIPS"
| wks.Cells(lLastRow + 1, 2).Formula = "=COUNTROWS(B:B) - 2"
| lLastRow = wks.Range("A1").End(xlDown).Row
| wks.PageSetup.PrintArea = "$A$1:$K$" & lLastRow
| lLastRow = wks.Range("A1").End(xlDown).Row
| Rows(lLastRow).Select
| Selection.Font.Bold = True
|
| With .PageSetup
|
| Page set up code
|
| End With
| .UsedRange.Rows.AutoFit
| End With
| Next wks
| End If
|
| More code down here.
|


  #3   Report Post  
Pank
 
Posts: n/a
Default

Jim,

Thanks it worked get. Also many thanks for the additional pointers.

Regards

Pank

"Jim Rech" wrote:

Replace the last two lines with this:

wks.Rows(lLastRow).Font.Bold = True

This will set the font of the last row of each sheet bold (I assume that
what you want).

No selecting is necessary (selecting will not even work anyway since you are
not activating each worksheet.

Also, no need to repeat:

lLastRow = wks.Range("A1").End(xlDown).Row

Once is enough. Also you start With wks and never use it.

--
Jim
"Pank" wrote in message
...
|I have the following macro, which works fine except for the two lines of
code
| before the With.PageSetup.
|
| Only the last row in the last worksheet in the workbook is set to bold.
All
| other sheets have the description TOTAL NUMBER OF SKIPS set in the last
row
| in Col A and a corresponding count in the last row in column b, but it is
not
| bolded.
|
| Any suggestions or ideas would be appreciated.
|
|
| Sub Format()
| Dim wks As Worksheet
| Dim lLastRow As Long
| Application.ScreenUpdating = False
|
| If ActiveSheet.Name < "MAIN" Then
|
| For Each wks In ActiveWorkbook.Worksheets
| With wks
|
| lLastRow = wks.Range("A1").End(xlDown).Row
| wks.Cells(lLastRow + 1, 1).Formula = "TOTAL NUMBER OF SKIPS"
| wks.Cells(lLastRow + 1, 2).Formula = "=COUNTROWS(B:B) - 2"
| lLastRow = wks.Range("A1").End(xlDown).Row
| wks.PageSetup.PrintArea = "$A$1:$K$" & lLastRow
| lLastRow = wks.Range("A1").End(xlDown).Row
| Rows(lLastRow).Select
| Selection.Font.Bold = True
|
| With .PageSetup
|
| Page set up code
|
| End With
| .UsedRange.Rows.AutoFit
| End With
| Next wks
| End If
|
| More code down here.
|



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
What's wrong with my array formula M.Siler Excel Discussion (Misc queries) 4 May 27th 05 09:19 PM
Wrong date on my posts. Gord Dibben Excel Discussion (Misc queries) 13 May 24th 05 11:00 AM
What is Wrong with this formula please? Issam LAdki New Users to Excel 4 March 9th 05 02:54 PM
What's wrong with this vb? DaveMoore Excel Worksheet Functions 2 February 24th 05 01:29 PM
I get wrong dates when i paste from a different sheet into a new s mmollat Excel Discussion (Misc queries) 2 January 6th 05 07:35 PM


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