Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Rob Rob is offline
external usenet poster
 
Posts: 718
Default VB Code Is Not Working

Hi,

I'm trying to make a code that alerts me when a cell is equal to today's
date. The message spits out the value of a cell that is adjacent to the
active cell but the code isn't working. Could someone please loot at it and
tell me where I went wrong?

Here's the Code:::

Private Sub Workbook_Open()
Dim Ws As Worksheets
Dim sRange As Range
Dim nDate As Date
Dim RowId As Integer
Dim lItem As Integer


Ws = Worksheets("Slabber Reports")
sRange = Ws("N8:N5000")
nDate = Today()
RowId = ActiveCell.Row

For Each Item In sRange
If sRange = nDate Then
lItem = Range("B & RowId & ").FormulaR1C1
MsgBox "Line Item " & lItem & " Is Now Active. Please Perform The Appropiate
Actions To Reflect This Activity", vbOKOnly
Next
Wend
MsgBox "That's All For Today", vbOKOnly
End If
End Sub


Thanks Very Much In Advance!!!
Rob
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default VB Code Is Not Working

Hi, Rob-
I made some changes to your code- with all due respect to your effort
I saw a couple problems in your original version. For instance,
Today() is not a VBA function by itself; I changed that to Int(Now())
which does what you needed it to do. Some other things: you have a
WEND with no WHILE, and your FOR EACH and IF structures overlap: the
IF needs to be self-contained within the FOR EACH, but your IF's END
IF occurs after the NEXT statement.

These points should have become clear when you attempted to compile or
run your code. If I may offer a tip, when you declare variables
include a capital letter in each, and when you enter VBA code type it
in all lower letters. That way when the compiler recognizes a reserved
word or one of your variables, you'll see a letter change case to
upper, and you can then be sure you typed it properly.

Please note some text wrapping may occur in this usenet post: if you
get a compile error you may need to fix a line that was wrapped in
posting.

Hope you'll accept this as the constructive message it was intended to
be~
Dave O

Private Sub Workbook_Open()
Dim rCell As Range

Sheets("Slabber Reports").Select
Range("n8:n5000").Select

For Each rCell In Selection.Cells
If rCell.Value = Int(Now()) Then
MsgBox "Line Item " & rCell.Address & " is now active. Please
perform the appropiate actions to reflect this activity.", vbOKOnly
End If
Next rCell

MsgBox "That's all for today.", vbOKOnly

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
Rob Rob is offline
external usenet poster
 
Posts: 718
Default VB Code Is Not Working

It works great and you used so much less code to do it as well.

Thanks Much!!

"Dave O" wrote:

Hi, Rob-
I made some changes to your code- with all due respect to your effort
I saw a couple problems in your original version. For instance,
Today() is not a VBA function by itself; I changed that to Int(Now())
which does what you needed it to do. Some other things: you have a
WEND with no WHILE, and your FOR EACH and IF structures overlap: the
IF needs to be self-contained within the FOR EACH, but your IF's END
IF occurs after the NEXT statement.

These points should have become clear when you attempted to compile or
run your code. If I may offer a tip, when you declare variables
include a capital letter in each, and when you enter VBA code type it
in all lower letters. That way when the compiler recognizes a reserved
word or one of your variables, you'll see a letter change case to
upper, and you can then be sure you typed it properly.

Please note some text wrapping may occur in this usenet post: if you
get a compile error you may need to fix a line that was wrapped in
posting.

Hope you'll accept this as the constructive message it was intended to
be~
Dave O

Private Sub Workbook_Open()
Dim rCell As Range

Sheets("Slabber Reports").Select
Range("n8:n5000").Select

For Each rCell In Selection.Cells
If rCell.Value = Int(Now()) Then
MsgBox "Line Item " & rCell.Address & " is now active. Please
perform the appropiate actions to reflect this activity.", vbOKOnly
End If
Next rCell

MsgBox "That's all for today.", vbOKOnly

End Sub


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
Calendar code not working RobN[_3_] Excel Discussion (Misc queries) 9 May 17th 07 05:48 AM
Filter isn't working with a VBA Code [email protected] Excel Worksheet Functions 8 June 15th 06 02:20 PM
Why code for find() is not working jesmin Excel Discussion (Misc queries) 1 December 28th 05 09:43 PM
Code not working and can't see why Steve Excel Discussion (Misc queries) 3 December 31st 04 04:12 PM
Often-Used Code not working in a new Workbook Steve Excel Discussion (Misc queries) 2 December 17th 04 12:55 AM


All times are GMT +1. The time now is 04:29 AM.

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"