Vba bug fix

adpatel

New Member
Joined
May 30, 2019
Messages
42
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone, I have a VBA code which is very simple, but still it's not working as it should be, so i think there is little bug in code, pls help to find it out

Requirement:-

If cell value is 0 or time is less than 15:29:00

than do nothing

else, 'Main code ll be run in this case'

My code:-

VBA Code:
Dim LTime As Date

   Sheets("AD").Select
    
    If Range("J2").Value = 0 Or LTime < "15:29:00" Then
    Range("K3").Select
    
    Else


Sheets("AD").Select

 Range("J2:AF3").Select
    Selection.Copy
 
    Range("J6").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Range("J6").Select
   
       
      End If


Any help ll be appriciated
 
@Zot you do need to use the Timevalue part as Now includes the date, so it includes the Integer part of the number.

For instance here it is 06:57 which is 0.289583333333333 without the date part.

Now would give 44210.289583333333333 which would be greater than TimeValue("03:29:00 PM") which is 0.645138888888889.
Ahhh .... forgot that Now has Date and Time... Thanks
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,216,069
Messages
6,128,599
Members
449,460
Latest member
jgharbawi

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