Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Macro issue with Merging Non-Contiguous Columns

I am creating an excel spreadsheet the produces various financial reports for
a client.

I have attached the following code to a control button.

When clicked the macro does the following:

1) Goes to a report sheet;
2) Hides certain columns in the sheet (the sheet contains many columns of
data which are only shown depending on the report the client wants to run)
3) Unhides only those columns that are relevant for the report the client
is running i.e. Month To Date and Year to Date information in this case)
4) Then the macro formats the TITLE rows so that they are merged across the
columns and thus centred on the report.

My problem comes about when dealing with non-contiguous column ranges and
the merging of the cells.

In the below example the MTDYTDReport named range includes columns D, F and H.

Therefore for some reason when the TITLE rows are merged they are not being
merged across all the columns.

Does anyone have an idea of how I can get around this??


Sub MTDYTDReport()
'
' This macro unhides the columns for the MTD, YTD Report
' Macro recorded 05/05/2006 by JTE
'
Sheets("P & L Branch").Select
Range("AllPLBranch").Select
Selection.EntireColumn.Hidden = True
Range("MTDYTDReport").Select
Selection.EntireColumn.Hidden = False
Range("MTDYTDReport1").Select
Selection.EntireColumn.Hidden = False

'This section will merge the titles to fit across all columns of report
Range("A2:X2").Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
Range("A3:X3").Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
Range("A4:X4").Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
Range("A5:X5").Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With

Range("A1").Select
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Macro issue with Merging Non-Contiguous Columns

You need to stick the horizontal alignment property in there someplace...
Selection.HorizontalAlignment = xlHAlignCenterAcrossSelection

Also, you don't have to merge the cells in order to center the text across
the columns. Just use the above line without the merge.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"James T"

wrote in message
I am creating an excel spreadsheet the produces various financial reports for
a client.
I have attached the following code to a control button.
When clicked the macro does the following:

1) Goes to a report sheet;
2) Hides certain columns in the sheet (the sheet contains many columns of
data which are only shown depending on the report the client wants to run)
3) Unhides only those columns that are relevant for the report the client
is running i.e. Month To Date and Year to Date information in this case)
4) Then the macro formats the TITLE rows so that they are merged across the
columns and thus centred on the report.
My problem comes about when dealing with non-contiguous column ranges and
the merging of the cells.
In the below example the MTDYTDReport named range includes columns D, F and H.

Therefore for some reason when the TITLE rows are merged they are not being
merged across all the columns.
Does anyone have an idea of how I can get around this??


Sub MTDYTDReport()
'
' This macro unhides the columns for the MTD, YTD Report
' Macro recorded 05/05/2006 by JTE
'
Sheets("P & L Branch").Select
Range("AllPLBranch").Select
Selection.EntireColumn.Hidden = True
Range("MTDYTDReport").Select
Selection.EntireColumn.Hidden = False
Range("MTDYTDReport1").Select
Selection.EntireColumn.Hidden = False

'This section will merge the titles to fit across all columns of report
Range("A2:X2").Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With

-snip-
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Macro issue with Merging Non-Contiguous Columns

Jim - Thank you. Simple solutions are the best.

Your help is appreciated.

Regards

James



"Jim Cone" wrote:

You need to stick the horizontal alignment property in there someplace...
Selection.HorizontalAlignment = xlHAlignCenterAcrossSelection

Also, you don't have to merge the cells in order to center the text across
the columns. Just use the above line without the merge.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"James T"

wrote in message
I am creating an excel spreadsheet the produces various financial reports for
a client.
I have attached the following code to a control button.
When clicked the macro does the following:

1) Goes to a report sheet;
2) Hides certain columns in the sheet (the sheet contains many columns of
data which are only shown depending on the report the client wants to run)
3) Unhides only those columns that are relevant for the report the client
is running i.e. Month To Date and Year to Date information in this case)
4) Then the macro formats the TITLE rows so that they are merged across the
columns and thus centred on the report.
My problem comes about when dealing with non-contiguous column ranges and
the merging of the cells.
In the below example the MTDYTDReport named range includes columns D, F and H.

Therefore for some reason when the TITLE rows are merged they are not being
merged across all the columns.
Does anyone have an idea of how I can get around this??


Sub MTDYTDReport()
'
' This macro unhides the columns for the MTD, YTD Report
' Macro recorded 05/05/2006 by JTE
'
Sheets("P & L Branch").Select
Range("AllPLBranch").Select
Selection.EntireColumn.Hidden = True
Range("MTDYTDReport").Select
Selection.EntireColumn.Hidden = False
Range("MTDYTDReport1").Select
Selection.EntireColumn.Hidden = False

'This section will merge the titles to fit across all columns of report
Range("A2:X2").Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With

-snip-

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
Cell Merging Issue IainB Excel Discussion (Misc queries) 3 July 13th 08 06:30 PM
Charting with non contiguous columns David Hopper Charts and Charting in Excel 3 April 7th 07 01:00 AM
Merging adjacent repeated columns with a macro [email protected] Excel Discussion (Misc queries) 2 April 3rd 07 07:44 PM
DCOUNT for non-contiguous columns RiotLoadTime Excel Worksheet Functions 4 July 3rd 06 03:12 PM
Macro to Combine 2 columns to make one column without merging JRM Excel Discussion (Misc queries) 1 December 31st 05 08:27 PM


All times are GMT +1. The time now is 02:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"