My Assistant
![]() ![]() |
|
|
Mar 26 2012, 03:49 PM
Post
#21
|
|
|
UtterAccess Certified! Posts: 6,928 From: Arizona, United States |
Are you saying to implement this idea in all of your code? That I"m not sure, I'm with Norie in terms of, there is too much Select and Activate type of thing. It is very very very preferable to avoid that and just take action on objects. I was just commenting on this discussion about finding the last used row, and I was soap-boxing my oft-repeated warning to avoid UsedRange or any similar thing.
But based on your recent post which already knows what it wants to do in plain english. So can't you just do the loop and repeat it 700 times? |
|
|
|
Mar 26 2012, 04:02 PM
Post
#22
|
|
|
UtterAccess Ruler Posts: 4,237 From: Downey, CA |
|
|
|
|
Mar 26 2012, 04:04 PM
Post
#23
|
|
|
UtterAccess Certified! Posts: 6,928 From: Arizona, United States |
Ok, so what do you have so far? and you want to go down to which specific row?
|
|
|
|
Mar 26 2012, 04:04 PM
Post
#24
|
|
|
UtterAccess Certified! Posts: 6,928 From: Arizona, United States |
Ok, so what do you have so far? and you want to go down to which specific row?
|
|
|
|
Mar 26 2012, 04:05 PM
Post
#25
|
|
|
UtterAccess Ruler Posts: 4,237 From: Downey, CA |
|
|
|
|
Mar 26 2012, 04:19 PM
Post
#26
|
|
|
UtterAccess Certified! Posts: 6,928 From: Arizona, United States |
Ok, let's try this first, using 99% of your original code, but with a change about the lastrow. I just want to qualify this solution by saying, due to time limitations I'm not writing this in what I think is an idea way. I'm sort of leaving most of the Select, etc., in place. (IMG:style_emoticons/default/frown.gif) But I believe it should work "most of the time", as code with Select and Activate is liable to work.
CODE Range("G2").Select Do Until ActiveCell.Row = 700 If IsEmpty(ActiveCell) = True Or IsDate(ActiveCell) = False Then ActiveCell.Offset(1, 0).Select Else If IsEmpty(Range("ListsNotes!g9")) = True Or IsDate(Range("ListsNotes!g9")) = False Then MsgBox "There is no date to compare" Exit Sub Else If ActiveCell < DateValue(Range("ListsNotes!g9")) Then ActiveCell.Offset(0, -1).Select ActiveCell.FormulaR1C1 = "D" ActiveCell.Offset(1, 1).Select Else ActiveCell.Offset(0, -1).Select ActiveCell.FormulaR1C1 = "A" ActiveCell.Offset(1, 1).Select End If End If End If Loop 'Go to top Range("A1").Select End Sub |
|
|
|
Mar 26 2012, 04:38 PM
Post
#27
|
|
|
UtterAccess Ruler Posts: 4,237 From: Downey, CA |
Isaac,
that worked like butter - took like 3 seconds to run..... I tested the dates - my next 'upgrade' is to make the report code (col F) more dynamic in a couple of ways: First of all, instead of all these hard-coded dates, will have like cur date minus 14 for weekly reports let's say, and at the same time cur date - 59 days for monthly reports, cur date minus 4 for daily reports so.... If: Frequency (Col H)........ Last run date (Col G)>>>>>>>>>>>>>> ACTION TAKEN --------------------..........------------------------ ....................................................... Daily/Weekly/Mnthly................... <null>..........................................go to next cell Daily....................................< cur date - 4...................................... Type "A" For active in col F if TRUE, "D" in Col F if FALSE Weekly....................................< cur date - 14...................................... Type "A" For active in col F if TRUE, "D" in Col F if FALSE Monthly....................................< cur date - 59...................................... Type "A" For active in col F if TRUE, "D" in Col F if FALSE But in the meantime, I celebrate !!!!! Thanks so much !!!! (IMG:style_emoticons/default/cool.gif) Steve |
|
|
|
Mar 26 2012, 04:40 PM
Post
#28
|
|
|
UtterAccess Certified! Posts: 6,928 From: Arizona, United States |
Glad to help
|
|
|
|
Mar 26 2012, 05:28 PM
Post
#29
|
|
|
UtterAccess VIP Posts: 4,295 |
You could do that with a series of If statements and use Offset to put the values in the cells as appropriate.
Something like this rough code. CODE Dim rng As Range TDATE = Worksheets("ListNotes").Range("G9").Value For I = 2 To lstrow Set rng = Range("G"& I) If rng.Value<>"" And IsDate(rng.Value) Then If rng.Value < TDATE Then rng.Offset(,-1).Value = "D" End If If rng.Value > TDATE Then rng.Offset(,-1).Value = "A" End If End If ' move to next cell in column G Next I Basically that goes through all the rows in column G. If the value in the cell is empty or not a date it moves on to the next cell. If it isn't empty and contains a date then it puts 'D' in the the value is less than TDATE, and if it's greater than TDATE put's an 'A'. Like I said the code is rough but I hope it makes some kind of sense:) |
|
|
|
Mar 26 2012, 06:06 PM
Post
#30
|
|
|
UtterAccess Ruler Posts: 4,237 From: Downey, CA |
norie,
I know this was just a rough example, and I can follow your lead, but was this supposed to do anything ? ( It doesn't - I attached an example ) Steve
Attached File(s)
|
|
|
|
Mar 26 2012, 06:27 PM
Post
#31
|
|
|
UtterAccess VIP Posts: 4,295 |
Since column G isn't always going to be fully opulated use another column such as A.
CODE Dim rng As Range TDATE = Worksheets("ListsNotes").Range("G9") For I = 2 To Range("A" & Rows.Count).End(xlUp).Row Set rng = Range("G" & I) If rng.Value <> "" And IsDate(rng.Value) Then If rng.Value < TDATE Then rng.Offset(, -1).Value = "D" End If If rng.Value > TDATE Then rng.Offset(, -1).Value = "A" End If End If Next I That does do something - it puts 'D' in F1 and 'A' in F5. |
|
|
|
Mar 26 2012, 06:33 PM
Post
#32
|
|
|
UtterAccess VIP Posts: 4,295 |
Oops, forgot to add a check for G9 on 'ListNotes'.
Add this just before the For...Next. CODE If TDATE = "" Or Not IsDate(TDATE) Then Exit Sub
|
|
|
|
Mar 26 2012, 06:54 PM
Post
#33
|
|
|
UtterAccess Ruler Posts: 4,237 From: Downey, CA |
|
|
|
|
Mar 26 2012, 07:10 PM
Post
#34
|
|
|
UtterAccess VIP Posts: 4,295 |
How exactly are you running the code?
I've made a few changes, mainly to make sure the code references the correct worksheet(s) and adding a couple of declarations. File attached.
Attached File(s)
|
|
|
|
Mar 27 2012, 06:33 AM
Post
#35
|
|
|
UtterAccess VIP Posts: 8,123 From: CT |
here is what I dont understand.
When I provided that original code in response to another thread, you said it was working exactly as you wanted. AND, it worked as tested. That included the "A" and the "D", what changed in your spreadsheet? Code just doesn't stop working unless something changed to the environment. EDIT: Other thread.. http://www.UtterAccess.com/forum/Evaluate-....html&st=20 |
|
|
|
Mar 27 2012, 06:52 AM
Post
#36
|
|
|
UtterAccess VIP Posts: 4,295 |
Bob
Which code, in this thread, do you mean by 'that'? |
|
|
|
Mar 27 2012, 07:32 AM
Post
#37
|
|
|
UtterAccess VIP Posts: 8,123 From: CT |
Norie,
The first post. The original version is mine. Which was provided in that other thread. Some techniques, good or bad, are easy to tell the author of. Bob |
|
|
|
Mar 27 2012, 09:42 AM
Post
#38
|
|
|
UtterAccess Ruler Posts: 4,237 From: Downey, CA |
bob - I honestly don't know - I'll just throw my hands up and say operator error - sometimes I put some code to use, and I see exactly what it (the code) is doing - other times, I'm not following the process - there was at least a couple of things going on I didn't understand - that was the case here where in trying to 'enhance' my code, and add functionality, things got 'broke' - for example, someone might give me a line of code as a solution, thinking, let's say that I'd know it was to REPLACE another line of code or 2 or 3 lines, and I just added it - just a hypothetical there - so not sure :-(
|
|
|
|
Mar 28 2012, 06:05 AM
Post
#39
|
|
|
UtterAccess VIP Posts: 4,295 |
Anybody try the code in the workbook I attached?
|
|
|
|
Mar 28 2012, 09:36 AM
Post
#40
|
|
|
UtterAccess Certified! Posts: 6,928 From: Arizona, United States |
well as long as this conversation is still active, let me add my question to the list of tomatoes being thrown in Steve's general direction - LOL, I'm just kidding - so Steve, the code I last posted , which was basically Bob's except I just added the # of times to loop - didn't you say it was working ??
|
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 21st May 2013 - 12:39 PM |