how do i add a second IF to end my macro if cell is no empty

Ratigan1970

New Member
Joined
Jan 22, 2024
Messages
7
Office Version
  1. 2010
Platform
  1. Windows
hello everyone in Excel land
im no pro at vba so ive come here to pick your brains
im making a clockin program in excel. it all works but the problem i have is you can clock in again after clocking in
so i thought id put a second IF or something to stop people clocking in again my mistake



VBA Code:
If Range("B2:AW32").Find(Range("A5")) Is Nothing Then
    MsgBox "Value not found"
Else
Range("A7").Select
Dim k As Date
k = Now
    ActiveCell.FormulaR1C1 = Format(k, "HH:MM")
    Range("A7").Select
    Selection.Copy
   Range("B2:AW32").Find(Range("A5")).Offset(0, 1).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Not clear to me what part of that applies to your situation. Code comments (notes) are often a good thing for people who can't see the rest of whatever you're posting. It may be as simple as Exit Sub right after you determine that there is already an entry (I assume for a particular date).
 
Upvote 0
hi micro sorry ill try and give more info
i thought a second IF to exit the macro if their was a time in the offset cell
in A7 is the date too lookup
in A5 is the time to copy
from B2 down i have 1-JAN TO 31-JAN then 4 colums over i have 1-Feb too 29-Feb and so on for the year
the macro finds the date and offsets from the date one to the right and pleases the time
i would like the macro to exit the sub if the offset cell has already got a time in it

hope this helps
 
Upvote 0
If A5 is where you want to look for a value and proceed only if there is one, maybe
VBA Code:
If Range("B2:AW32").Find(Range("A5")).Offset(0, 1)<> "" Then
   Range("B2:AW32").Find(Range("A5")).Offset(0, 1).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    etc. etc.
End if
Not the most efficient approach but simplest for you to work with I think. Things still are not clear to me.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top