LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Select Column based on Sheet Name

Add a line after:
ActiveSheet.Columns(Rng.Column).Select
ActiveSheet.Columns(Rng.Column).Font.bold = true

If you want to do more, try recording a macro when you do it manually. It may
make it easy to wedge it into your code.

Bugaboo wrote:

Your code selects the right column. Now how do I get it to bold it?

"Dave Peterson" wrote:

Did you try the code I suggested?

Bugaboo wrote:

Jeff's code works if I run it on each sheet. I am not sure where I would put
the code to have it select and bold when creating the sheets.

"Dave Peterson" wrote:

What happened when you tried the code?

Bugaboo wrote:

Your assumption was correct.

"Dave Peterson" wrote:

The assumption I made is correct or the macro worked ok?

Or maybe both????

Bugaboo wrote:

Dave,

That is correct.

"Dave Peterson" wrote:

Each time you create a new worksheet, then that worksheet should have the column
that the was used for the name of the new worksheet.

If the name is in X1, then column X should be selected, right?

Option Explicit
Sub DCreateNameSheets()

Dim wsTemp As Worksheet
Dim Rng As Range
Dim ListRng As Range
Dim iCol As Long

Set wsTemp = Worksheets("Transposed")

With wsTemp
Set ListRng = .Range("B1", .Range("B1").End(xlToRight))
End With

For Each Rng In ListRng.Cells
If Rng.Text < "" Then
wsTemp.Copy After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = Rng.Text
ActiveSheet.Columns(Rng.Column).Select
End If
Next Rng
End Sub


Bugaboo wrote:

Jeff,

That would be great if I can get it to do it while creating the sheets. I'm
just not sure where it would go.

Here is the code I am using to create my sheets:

Sub DCreateNameSheets()

Dim wstemp As Worksheet
Dim Rng As Range
Dim ListRng As Range
Set wstemp = Worksheets("Transposed")
Set ListRng = Range(Range("B1"), Range("B1").End(xlToRight))
For Each Rng In ListRng
If Rng.Text < "" Then
wstemp.Copy After:=Worksheets(Worksheets.Count)
Worksheets(Worksheets.Count).Name = Rng.Text
End If
Next Rng
End Sub

"Jeff Johnson" wrote:

"Bugaboo" wrote in message
...

I have a macro that will copy and add a sheet, and name it for each name in
the first row.

I now need to select the column in each sheet where the sheet name and
header name are the same and set the background to gray. The number of
columns and rows will vary.

Is this possible to do?

Yes, and I'll show you how, but why not do it WHILE you're creating your
copies? Yoiu'll already know which column you're dealing with, and it'll
make the following code mostly unnecessary. By the way, "set the background
to gray" is vague, so I'm setting the fill color of entire column to gray.
If you want something more specific, give more specific requirements.

Dim sheetName As String
Dim x As Long

sheetName = ActiveSheet.Name

For x = 1 To 256 ' (Or however many header columns you have)
If ActiveSheet.Cells(1, x).Text = sheetName Then
ActiveSheet.Cells(1, x).EntireColumn.Interior.Color = RGB(192, 192,
192)
Exit Sub
End If
Next




--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
 
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
Select sheet based on cell value Boss Excel Programming 3 January 30th 08 02:55 PM
How do I select a cell based on the Column name Teresa K. Excel Programming 3 November 28th 06 11:02 PM
Select a column based on a index VH Excel Programming 5 March 6th 06 09:40 AM
Select sheet based on reference Hans Weustink[_4_] Excel Programming 11 January 11th 05 01:05 PM
Select sheet based on cell value Dan Mills Excel Programming 2 January 14th 04 05:55 PM


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