Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Beginner question (I hope)

Hey guys I've been in other areas of this forum (can even answer a few
questions) but I'm not much when it comes to visual basic so here is
my question...

I have a small macro to format a few ugly reports and I have one
problem, the Date column moves from report to report and the date
comes in the general format (i.e. 38098) so I put together this little
macro :

Rows("1:1").Select '(headers are always row 1)
Selection.Find(What:="date", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Columns("A:A").EntireColumn.Select
ActiveCell.Offset(1, 0).Range("A1").Activate
Selection.NumberFormat = "mm/dd/yy"

My problem is that IF there is no date it of course fails and a pop up
window comes up Since I have to share this macro with others I was
wondering if there is any way to put in a statement that if the Find
does not find anything if it can just end. This is the last of the
lines of code so if it is just a full stop that is ok. If we were in
Excel I'd put something like IF(ISERROR(find) = true, STOP,highlight
and format the column) but I'm not sure how to do that in visual
basic.

Any help would be much appreciated and thanks in advance for any help.

Chad
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Beginner question (I hope)

Chad,

Use firnd to set a range, and check for its existence prior to the
formatting step:

Dim myCell As Range
Set myCell = Rows("1:1").Find(What:="date", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not myCell Is Nothing Then
myCeell.EntireColumn.NumberFormat = "mm/dd/yy"
End if

HTH,
Bernie
MS Excel MVP

"chadt74" wrote in message
m...
Hey guys I've been in other areas of this forum (can even answer a few
questions) but I'm not much when it comes to visual basic so here is
my question...

I have a small macro to format a few ugly reports and I have one
problem, the Date column moves from report to report and the date
comes in the general format (i.e. 38098) so I put together this little
macro :

Rows("1:1").Select '(headers are always row 1)
Selection.Find(What:="date", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Columns("A:A").EntireColumn.Select
ActiveCell.Offset(1, 0).Range("A1").Activate
Selection.NumberFormat = "mm/dd/yy"

My problem is that IF there is no date it of course fails and a pop up
window comes up Since I have to share this macro with others I was
wondering if there is any way to put in a statement that if the Find
does not find anything if it can just end. This is the last of the
lines of code so if it is just a full stop that is ok. If we were in
Excel I'd put something like IF(ISERROR(find) = true, STOP,highlight
and format the column) but I'm not sure how to do that in visual
basic.

Any help would be much appreciated and thanks in advance for any help.

Chad



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Beginner question (I hope)

Bernie, thanks so much for your help. With your code I was able to
get the results that I needed and even add a few more searches to my
macro.

Thanks again!!
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
Beginner Question Bernie Charts and Charting in Excel 0 February 13th 07 04:31 PM
Beginner question! Pat Excel Discussion (Misc queries) 3 August 7th 06 09:19 AM
Beginner question Tom. Excel Discussion (Misc queries) 1 April 24th 06 06:08 AM
Templete question...I hope there is an answer Rookie000 Excel Worksheet Functions 3 January 15th 06 04:04 AM
VLOOKUP() Question... i hope Adam Kroger Excel Discussion (Misc queries) 2 November 29th 05 10:22 PM


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