PC Review


Reply
Thread Tools Rate Thread

How to add condition to coding?

 
 
Eric
Guest
Posts: n/a
 
      23rd Mar 2009
Does anyone have any suggestions on how to add condition into coding?

I would like to add the condition, please see []
If wkbk Is Nothing [and myCell.Offset(0, 2).Value is not equal today] Then
Thanks in advance for any suggestions
Eric

======================================
Original Coding
======================================

Option Explicit
Sub Updating_Lists()

Dim myRng As Range
Dim myCell As Range
Dim wkbk As Workbook

With Worksheets("Table").Range("C3")
.NumberFormat = "hh:mm AM/PM"
.Value = Now
End With

With Worksheets("Lists")
'still starting in row 2!
Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each myCell In myRng.Cells
Set wkbk = Nothing
On Error Resume Next
On Error GoTo 0
myCell.Offset(0, 1).Value = ""

Next myCell

For Each myCell In myRng.Cells
Set wkbk = Nothing
On Error Resume Next
Set wkbk = Workbooks.Open(Filename:=myCell.Value, UpdateLinks:=3)
On Error GoTo 0

<<< Add the condition here >>>

If wkbk Is Nothing Then

<<< Add the condition here >>>

myCell.Offset(0, 1).Value = "Failed to open!"
Else
wkbk.Close savechanges:=True
myCell.Offset(0, 1).Value = "ok"
With myCell.Offset(0, 2)
.NumberFormat = "mm/dd/yyyy"
.Value = Date
End With
With myCell.Offset(0, 3)
.NumberFormat = "hh:mm:ss"
.Value = Time
End With

End If
Next myCell

With Worksheets("Table").Range("E3")
.NumberFormat = "hh:mm AM/PM"
.Value = Now
End With

'better to include an extension
Workbooks("Update Up.xls").Close savechanges:=True

End Sub

 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      23rd Mar 2009
Hi Eric,

If wkbk Is Nothing And myCell.Offset(0, 2).Value <> Date Then

--
Regards,

OssieMac


"Eric" wrote:

> Does anyone have any suggestions on how to add condition into coding?
>
> I would like to add the condition, please see []
> If wkbk Is Nothing [and myCell.Offset(0, 2).Value is not equal today] Then
> Thanks in advance for any suggestions
> Eric
>
> ======================================
> Original Coding
> ======================================
>
> Option Explicit
> Sub Updating_Lists()
>
> Dim myRng As Range
> Dim myCell As Range
> Dim wkbk As Workbook
>
> With Worksheets("Table").Range("C3")
> .NumberFormat = "hh:mm AM/PM"
> .Value = Now
> End With
>
> With Worksheets("Lists")
> 'still starting in row 2!
> Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
> End With
>
> For Each myCell In myRng.Cells
> Set wkbk = Nothing
> On Error Resume Next
> On Error GoTo 0
> myCell.Offset(0, 1).Value = ""
>
> Next myCell
>
> For Each myCell In myRng.Cells
> Set wkbk = Nothing
> On Error Resume Next
> Set wkbk = Workbooks.Open(Filename:=myCell.Value, UpdateLinks:=3)
> On Error GoTo 0
>
> <<< Add the condition here >>>
>
> If wkbk Is Nothing Then
>
> <<< Add the condition here >>>
>
> myCell.Offset(0, 1).Value = "Failed to open!"
> Else
> wkbk.Close savechanges:=True
> myCell.Offset(0, 1).Value = "ok"
> With myCell.Offset(0, 2)
> .NumberFormat = "mm/dd/yyyy"
> .Value = Date
> End With
> With myCell.Offset(0, 3)
> .NumberFormat = "hh:mm:ss"
> .Value = Time
> End With
>
> End If
> Next myCell
>
> With Worksheets("Table").Range("E3")
> .NumberFormat = "hh:mm AM/PM"
> .Value = Now
> End With
>
> 'better to include an extension
> Workbooks("Update Up.xls").Close savechanges:=True
>
> End Sub
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add condition to coding? Eric Microsoft Excel Programming 5 23rd Mar 2009 06:15 AM
Color Coding by Condition claire.venturino@gmail.com Microsoft Excel Discussion 1 8th May 2008 05:36 PM
Coding "record found" condition =?Utf-8?B?anViZQ==?= Microsoft Access Form Coding 1 23rd Mar 2006 01:32 PM
visible coding with condition =?Utf-8?B?ZWR3YXJkIGtlaXRo?= Microsoft Access Form Coding 5 20th Feb 2006 04:56 AM
Coding for Reports - making a symbol appear on a condition =?Utf-8?B?SmVzc2U=?= Microsoft Access Reports 0 3rd Mar 2005 10:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:37 PM.