|
-
Dec 9th, 2016, 01:25 AM
#1
Thread Starter
Junior Member
[RESOLVED] Find Date
Hi,
In Sheet1, I want to get following: -
1. find yesterday's date
2. address of first cell containing yesterday's date
3. row number of first cell containing yesterday's date
4. column number of first cell containing yesterday's date
5. using column number from step 4, I want to remove all values from cells in that column, which do not contain any time.
I have clues about Step 1, 3 and 4.
But, I am not able to link Step 1 to 5 together.
With thanks,
Sukumar
-
Dec 9th, 2016, 02:57 AM
#2
Re: Find Date
I want to remove all values from cells in that column, which do not contain any time
pls explain more
use excels find method for 2.
maybe like
Code:
Set fnd = s.UsedRange.Find(Date - 1)
rw = fnd.row
col = fnd.column
where s is a worksheet object
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 9th, 2016, 04:29 AM
#3
Thread Starter
Junior Member
Re: Find Date
 Originally Posted by sukumar
Hi,
In Sheet1, I want to get following: -
1. find yesterday's date
2. address of first cell containing yesterday's date
3. row number of first cell containing yesterday's date
4. column number of first cell containing yesterday's date
5. using column number from step 4, I want to remove all values from cells in that column, which do not contain any time.
I have clues about Step 1, 3 and 4.
But, I am not able to link Step 1 to 5 together.
With thanks,
Sukumar
Hi,
Lets say about Step 1,
Code:
td = Format(Date -1, "dd-mm-yyyy")
Lets say about step 2, (which gave error)
Code:
Cells.Find(What:="09-Dec-16", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Lets say about Step 3
I need to put some formula to extract Column number.
Lets say about Step 5.
Please refer to attachment here Attachment 143145, where Range("G15") and Range("G20") contain text values, which I want to remove, and replace by Time Values.
With thanks,
Sukumar
-
Dec 9th, 2016, 06:24 AM
#4
Re: Find Date
Cells.Find(What:="09-Dec-16",
this searches for a text string and may not match a date value, even though they look the same
I need to put some formula to extract Column number.
activecell.column
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 9th, 2016, 07:22 AM
#5
Thread Starter
Junior Member
Re: Find Date
 Originally Posted by westconn1
this searches for a text string and may not match a date value, even though they look the same
Hi,
I thank you for feedback. Please help with Solution.
With thanks,
Sukumar
-
Dec 9th, 2016, 07:55 AM
#6
Re: Find Date
I'm unclear what you mean by step 5, but:
Code:
Sub findDate()
Dim ws As Worksheet
Dim fnd As Range
Set ws = ActiveSheet
Set fnd = ws.UsedRange.Find(Date - 1)
MsgBox fnd.Address & vbCrLf & fnd.Row & vbCrLf & fnd.Column
'the above shows the address, the row and the column
With ws.Columns(fnd.Column)
'what does "not contain any time" mean?
End With
End Sub
-
Dec 9th, 2016, 04:41 PM
#7
Re: Find Date
Please help with Solution.
see post #2
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 10th, 2016, 12:49 AM
#8
Thread Starter
Junior Member
Re: Find Date
Excellent job until here, but experts put unreliable remarks for usedrange questionable
 Originally Posted by vbfbryce
I'm unclear what you mean by step 5, but:
Code:
With ws.Columns(fnd.Column)
'what does "not contain any time" mean?
End With
End Sub
Let me explain steps for 'what does "not contain any time" mean?
Step1: Code found first row as fnd.row
Step 2: Code to filter fnd.row and filter out only Text Values, but not time values in fnd.column
Step 3: Code to Delete all rows which have Text Value, but not time values in fnd.column
With thanks,
Sukumar
-
Dec 10th, 2016, 05:48 AM
#9
Thread Starter
Junior Member
Re: Find Date
 Originally Posted by sukumar
Please refer to attachment here Attachment 143145, where Range("G15") and Range("G20") contain text values, which I want to remove, and replace by Time Values.
Following URL address explains why Run Time Error 91 happens.
-
Dec 10th, 2016, 06:03 AM
#10
Re: Find Date
experts put unreliable remarks for usedrange
but in this case it will not affect the results
you can test each cel in fnd.column, to see if it is a time only value like
Code:
ndrow = Cells(Rows.Count, fnd.Column).End(xlUp).Row
For rw = ndrow To 2 Step -1
If IsDate(Cells(rw, fnd.Column).Text) And Cells(rw, fnd.Column).Value2 < 1 Then
' time value, do nothing
Else
Cells(rw, 1).EntireRow.Delete
End If
Next
not properly tested, but runs without error
note this will also delete the row with yesterdays date as it is in the column being checked
i specified to check to row 2 if no headers change to row 1
if this is incorrect then the information was not clear
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|