VBA Using subroutines - help please
Solved/Closed
BrianGreen
Posts
1005
Registration date
Saturday January 17, 2015
Status
Moderator
Last seen
September 30, 2021
-
Feb 5, 2016 at 02:59 PM
BrianGreen Posts 1005 Registration date Saturday January 17, 2015 Status Moderator Last seen September 30, 2021 - Feb 10, 2016 at 12:57 AM
BrianGreen Posts 1005 Registration date Saturday January 17, 2015 Status Moderator Last seen September 30, 2021 - Feb 10, 2016 at 12:57 AM
Related:
- VBA Using subroutines - help please
- Vba case like - Guide
- Number to words in excel formula without vba - Guide
- Vba check if value is in array - Guide
- Vba color index - Guide
- How to open vba in excel mac - Guide
2 responses
BrianGreen
Posts
1005
Registration date
Saturday January 17, 2015
Status
Moderator
Last seen
September 30, 2021
149
Feb 6, 2016 at 10:35 AM
Feb 6, 2016 at 10:35 AM
RayH
You are a star. It works just as I needed it to (until I mess it up with the next bit I have to do). The only thing I needed to do was add a "Global Nearly As Date" as the second line.
It is clear I need to find out about SUBs and the thing you added at the top "Global variable? as a thing" - where do you suggest I can find out about these in an easy to learn source? most of what I have learned is from examples on the net or this forum (thanks guys).
How many virtual beers do you think you can cope with? - here's one to get you started ...
I really appreciate thank you messages as a payment for solving issues :o)
You are a star. It works just as I needed it to (until I mess it up with the next bit I have to do). The only thing I needed to do was add a "Global Nearly As Date" as the second line.
It is clear I need to find out about SUBs and the thing you added at the top "Global variable? as a thing" - where do you suggest I can find out about these in an easy to learn source? most of what I have learned is from examples on the net or this forum (thanks guys).
How many virtual beers do you think you can cope with? - here's one to get you started ...
I really appreciate thank you messages as a payment for solving issues :o)
Does this work?
Global MyDay As Date Sub ImportantStuff() Dim Rng As Range MyDay = DateAdd("yyyy", -1, Date) Nearly = MyDay + 7 Set Rng = ActiveSheet.Range("D6:D10,G6:G10") Call CheckDates(Rng) Set Rng = Sheet2.Range("D6:D10,G6:G10") Call CheckDates(Rng) End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub CheckDates(myrange As Range) For Each x In myrange.Cells If x < MyDay Then Cells(15, 5) = x ElseIf x < Nearly Then Cells(15, 4) = x Else: Cells(15, 3) = x End If Next End Sub
Feb 6, 2016 at 12:23 PM
t would be nice to know what is happening on the date that has been copied (especially the hospital appointments and the bills). How do I get the data from the cell next to the date in the range and put it in the cell to the left of the date just listed? I have tried an offset, but not sure Im using it correctly, but even more unsure that I can get the cell address that has the date in.
I have made room for this new data, so what I have now is this (I have commented the bit where I think I would get the extra required data from)
Cocktails for you if you do this - perhaps on a sunny beach.
Feb 7, 2016 at 10:46 PM
Can you post a sample of what you have in the sheets I would help a great deal.
Testing with imaginary data isn't that easy.
Feb 8, 2016 at 01:31 PM
Unfortunately I cant do post the sheets until Wednesday morning, but if you are happy for me to describe it here, then here goes ...
Cells D6 to D10 and Cells G6 to G10 (and every third column after) on every sheet have the date of an appointment.
Cells C6 to C10 and Cells F6 to F10 (and every third column after) on every sheet have the description of the appointment.
Graphically it looks like this:
................ D .............| .......E ........| ...........F.........| ..........G........| ........H.......|
Go to Fred's house | 01/24/216 | [Empty Cell] | My Birthday | 15/03/2016 |
Buy Tim a pint or 2 | 07/3/2016 | [Empty Cell] | RayH Medal | 09/02/2016 |
.....
So far we (you) have managed to pull the date for me, but it would be nice to see what is associated with the date so I would need the output to be:
RayH Medal | 09/02/2016 |
rather than just
| 09/02/2016 |
I hope thats enough.
Feb 8, 2016 at 02:34 PM
You can add this line to pull the description of the appointment:
e.g.
Cells(finalrowOverdue + 1, 8) = x.Offset(0, -1).Value
It takes the cell appointment description from the left of the date.
The others are:
Cells(finalrowComingUp + 1, 5) = x.Offset(0, -1).Value
and
Cells(finalrowCBooked + 1, 2) = x.Offset(0, -1).Value
see how you get on with that.
Feb 10, 2016 at 12:57 AM
That must have been the only combination of Offset that I didnt try! (well almost!)
The only thing about offering you a cocktail on the beach is that I have to go as well (or else I cant get you one.. Thats not bad in itself, but I'll have to bring the wife. Im not sure you'd like that!
Heres the cocktails anyway ...