Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Alternative to blind formatting

Currently I am using a macro to format column E for a number sequence, but I
am receiving new sheets where the info that normally is in column E is in
another column.

Is it possible to modify this code to only format columns in which the
column header is labeled as "Subject ID"?

Columns("E:E").Select
Selection.NumberFormat = "000000000000000 "

End Sub
Sub FormatSheets()
For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
ws.Columns("E:E").NumberFormat = "000000000000000"
Next ws
End Sub

Thanks

Fred
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Alternative to blind formatting

If you are certain that Subject ID is found on every sheet....

Sub FormatSheets()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Cells.Find("Subject ID").EntireColumn.NumberFormat = "000000000000000"
Next ws
End Sub

HTH,
Bernie
MS Excel MVP


"fgwiii" wrote in message
...
Currently I am using a macro to format column E for a number sequence, but I
am receiving new sheets where the info that normally is in column E is in
another column.

Is it possible to modify this code to only format columns in which the
column header is labeled as "Subject ID"?

Columns("E:E").Select
Selection.NumberFormat = "000000000000000 "

End Sub
Sub FormatSheets()
For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
ws.Columns("E:E").NumberFormat = "000000000000000"
Next ws
End Sub

Thanks

Fred



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Alternative to blind formatting

Try this. It requires you to pass the header row into the function that
returns the appropriate column. This code assumes only one column will be
labeled Subject ID... The error handling is in case there is no Subject ID in
the header row.

Sub FormatSheets()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
On Error Resume Next
SubjectIDColumn(ws.Rows(1)).NumberFormat = "000000000000000"
On Error GoTo 0
Next ws
End Sub

Private Function SubjectIDColumn(ByVal rngHeader As Range) As Range

Set SubjectIDColumn = rngHeader.Find(What:="Subject ID", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False).EntireColumn
End Function
--
HTH...

Jim Thomlinson


"fgwiii" wrote:

Currently I am using a macro to format column E for a number sequence, but I
am receiving new sheets where the info that normally is in column E is in
another column.

Is it possible to modify this code to only format columns in which the
column header is labeled as "Subject ID"?

Columns("E:E").Select
Selection.NumberFormat = "000000000000000 "

End Sub
Sub FormatSheets()
For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
ws.Columns("E:E").NumberFormat = "000000000000000"
Next ws
End Sub

Thanks

Fred

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Alternative to blind formatting

That work fine - but upon a closer look at the column headers I did find
where some of the headers for the subject state "Patient ID" or something
else. Is there a clean way of handling this or should I just create a new
macro for each issue?

Thank you!

Fred

"Jim Thomlinson" wrote:

Try this. It requires you to pass the header row into the function that
returns the appropriate column. This code assumes only one column will be
labeled Subject ID... The error handling is in case there is no Subject ID in
the header row.

Sub FormatSheets()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
On Error Resume Next
SubjectIDColumn(ws.Rows(1)).NumberFormat = "000000000000000"
On Error GoTo 0
Next ws
End Sub

Private Function SubjectIDColumn(ByVal rngHeader As Range) As Range

Set SubjectIDColumn = rngHeader.Find(What:="Subject ID", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False).EntireColumn
End Function
--
HTH...

Jim Thomlinson


"fgwiii" wrote:

Currently I am using a macro to format column E for a number sequence, but I
am receiving new sheets where the info that normally is in column E is in
another column.

Is it possible to modify this code to only format columns in which the
column header is labeled as "Subject ID"?

Columns("E:E").Select
Selection.NumberFormat = "000000000000000 "

End Sub
Sub FormatSheets()
For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
ws.Columns("E:E").NumberFormat = "000000000000000"
Next ws
End Sub

Thanks

Fred

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Alternative to blind formatting

That is why the making this a function is so handy. Try the followin change...

Sub FormatSheets()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
On Error Resume Next
SubjectIDColumn(ws.Rows(1), "Subject ID").NumberFormat =
"000000000000000"
SubjectIDColumn(ws.Rows(1), "Patient ID").NumberFormat =
"000000000000000"
On Error GoTo 0
Next ws
End Sub

Private Function SubjectIDColumn(ByVal rngHeader As Range, byval str as
string) As Range

Set SubjectIDColumn = rngHeader.Find(What:=str, _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False).EntireColumn
End Function

--
HTH...

Jim Thomlinson


"fgwiii" wrote:

That work fine - but upon a closer look at the column headers I did find
where some of the headers for the subject state "Patient ID" or something
else. Is there a clean way of handling this or should I just create a new
macro for each issue?

Thank you!

Fred

"Jim Thomlinson" wrote:

Try this. It requires you to pass the header row into the function that
returns the appropriate column. This code assumes only one column will be
labeled Subject ID... The error handling is in case there is no Subject ID in
the header row.

Sub FormatSheets()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
On Error Resume Next
SubjectIDColumn(ws.Rows(1)).NumberFormat = "000000000000000"
On Error GoTo 0
Next ws
End Sub

Private Function SubjectIDColumn(ByVal rngHeader As Range) As Range

Set SubjectIDColumn = rngHeader.Find(What:="Subject ID", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False).EntireColumn
End Function
--
HTH...

Jim Thomlinson


"fgwiii" wrote:

Currently I am using a macro to format column E for a number sequence, but I
am receiving new sheets where the info that normally is in column E is in
another column.

Is it possible to modify this code to only format columns in which the
column header is labeled as "Subject ID"?

Columns("E:E").Select
Selection.NumberFormat = "000000000000000 "

End Sub
Sub FormatSheets()
For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
ws.Columns("E:E").NumberFormat = "000000000000000"
Next ws
End Sub

Thanks

Fred



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Alternative to blind formatting

Jim,

When I attempt to run this it gets errors.

Thanks
Fred

"Jim Thomlinson" wrote:

That is why the making this a function is so handy. Try the followin change...

Sub FormatSheets()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
On Error Resume Next
SubjectIDColumn(ws.Rows(1), "Subject ID").NumberFormat =
"000000000000000"
SubjectIDColumn(ws.Rows(1), "Patient ID").NumberFormat =
"000000000000000"
On Error GoTo 0
Next ws
End Sub

Private Function SubjectIDColumn(ByVal rngHeader As Range, byval str as
string) As Range

Set SubjectIDColumn = rngHeader.Find(What:=str, _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False).EntireColumn
End Function

--
HTH...

Jim Thomlinson


"fgwiii" wrote:

That work fine - but upon a closer look at the column headers I did find
where some of the headers for the subject state "Patient ID" or something
else. Is there a clean way of handling this or should I just create a new
macro for each issue?

Thank you!

Fred

"Jim Thomlinson" wrote:

Try this. It requires you to pass the header row into the function that
returns the appropriate column. This code assumes only one column will be
labeled Subject ID... The error handling is in case there is no Subject ID in
the header row.

Sub FormatSheets()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
On Error Resume Next
SubjectIDColumn(ws.Rows(1)).NumberFormat = "000000000000000"
On Error GoTo 0
Next ws
End Sub

Private Function SubjectIDColumn(ByVal rngHeader As Range) As Range

Set SubjectIDColumn = rngHeader.Find(What:="Subject ID", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False).EntireColumn
End Function
--
HTH...

Jim Thomlinson


"fgwiii" wrote:

Currently I am using a macro to format column E for a number sequence, but I
am receiving new sheets where the info that normally is in column E is in
another column.

Is it possible to modify this code to only format columns in which the
column header is labeled as "Subject ID"?

Columns("E:E").Select
Selection.NumberFormat = "000000000000000 "

End Sub
Sub FormatSheets()
For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
ws.Columns("E:E").NumberFormat = "000000000000000"
Next ws
End Sub

Thanks

Fred

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Alternative to blind formatting

The text wrapped in the browser. You need to clean up the added carriage
returns.
--
HTH...

Jim Thomlinson


"fgwiii" wrote:

Jim,

When I attempt to run this it gets errors.

Thanks
Fred

"Jim Thomlinson" wrote:

That is why the making this a function is so handy. Try the followin change...

Sub FormatSheets()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
On Error Resume Next
SubjectIDColumn(ws.Rows(1), "Subject ID").NumberFormat =
"000000000000000"
SubjectIDColumn(ws.Rows(1), "Patient ID").NumberFormat =
"000000000000000"
On Error GoTo 0
Next ws
End Sub

Private Function SubjectIDColumn(ByVal rngHeader As Range, byval str as
string) As Range

Set SubjectIDColumn = rngHeader.Find(What:=str, _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False).EntireColumn
End Function

--
HTH...

Jim Thomlinson


"fgwiii" wrote:

That work fine - but upon a closer look at the column headers I did find
where some of the headers for the subject state "Patient ID" or something
else. Is there a clean way of handling this or should I just create a new
macro for each issue?

Thank you!

Fred

"Jim Thomlinson" wrote:

Try this. It requires you to pass the header row into the function that
returns the appropriate column. This code assumes only one column will be
labeled Subject ID... The error handling is in case there is no Subject ID in
the header row.

Sub FormatSheets()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
On Error Resume Next
SubjectIDColumn(ws.Rows(1)).NumberFormat = "000000000000000"
On Error GoTo 0
Next ws
End Sub

Private Function SubjectIDColumn(ByVal rngHeader As Range) As Range

Set SubjectIDColumn = rngHeader.Find(What:="Subject ID", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False).EntireColumn
End Function
--
HTH...

Jim Thomlinson


"fgwiii" wrote:

Currently I am using a macro to format column E for a number sequence, but I
am receiving new sheets where the info that normally is in column E is in
another column.

Is it possible to modify this code to only format columns in which the
column header is labeled as "Subject ID"?

Columns("E:E").Select
Selection.NumberFormat = "000000000000000 "

End Sub
Sub FormatSheets()
For Each ws In Worksheets
ws.Rows(1).Font.ColorIndex = 2
ws.Columns("E:E").NumberFormat = "000000000000000"
Next ws
End Sub

Thanks

Fred

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
Set Range.....am I to blind? carlo Excel Programming 13 November 29th 07 01:58 PM
Excel add-in that may help the color blind Jim Cone Excel Programming 9 July 6th 06 12:59 PM
Blind Carbon Copy (Bcc) Wayne Excel Discussion (Misc queries) 2 February 15th 06 01:56 AM
Excel for Blind persons use DeDe Excel Discussion (Misc queries) 1 February 8th 06 05:22 PM
Alternative to Conditional Formatting Bruise Excel Programming 9 October 23rd 05 01:06 AM


All times are GMT +1. The time now is 01:13 AM.

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"