MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 18th, 2002, 01:48 AM   #1
TroyBoy
New Member
 
Join Date: May 2002
Posts: 9
Default

Hi,

I've been reading through the archives, and have run into ~similar~ problems, but nothing quite like this. I would like to increment a date by one month by clicking a button. I have done the(in a sub):

Range("A2").Value=Range("A2").Value +1

which increments by 1 day.

Then I have tried(in a sub):

Range("A2").Value=DATE(YEAR(A2),MONTH(A2)+1,DAY(A2))

Which gives me a syntax error of ) expected after YEAR.

What I am trying to do overall is click a button, the cell A2 will increment forward by one month, cells B4 through AF4 will increment forward by one month, and cells B5 through AF5 will change days (as in days of the week) with the change of the month.

Could anyone help me with this?

Thanks,

Troy
TroyBoy is offline   Reply With Quote
Old May 18th, 2002, 02:11 AM   #2
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Try this Troy...

Range("A2") = DateAdd("m", 1, Range("A2"))

If any problems, use this:

Range("A2").Value = DateAdd("m", 1, Range("A2").Value)

Tom
Tom Schreiner is offline   Reply With Quote
Old May 18th, 2002, 02:15 AM   #3
TroyBoy
New Member
 
Join Date: May 2002
Posts: 9
Default

WOW!

Free (Virtual)Beer for you Tom!

Thanks Muy!

Troy
TroyBoy is offline   Reply With Quote
Old May 18th, 2002, 03:39 AM   #4
TroyBoy
New Member
 
Join Date: May 2002
Posts: 9
Default

Hmmmm... well, it took care of cell A2... now for Range("B4:AF4"). I get a type mismatch error if I substitute Range("B4:AF4") in the formula. I ~think~ I've made all of the obvious mistakes in the past hour or so:

Range("B4:AF4") = DateAdd("m", 1, Range("A2"))

This ended up incrementing the B4:AF4 range by two years

Range("B4:AF4") = Range("A2"

This ended up making all dates the same as A2

Let's see... what else. Oh, I tried the Union thing:

Dim r1 as range, r2 as range, myrange as range

set r1 = ("A2")
set r2 = ("B4:AF4")
myrange = Union(r1,r2)


myrange=DateAdd("m", 1, Range("A2"))

Would the union thing work if I put a date in a different cell and ref'd that?

myrange=DateAdd("m", 1, Range("z1"))

Awwww heck... back to work!

Thanks,
Troy
TroyBoy is offline   Reply With Quote
Old May 18th, 2002, 03:44 AM   #5
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

What are you trying to do in B4:AF4?
Do all of the cells in this range = A2?
or
Are you trying to increment the date by one month in each of these cells, each having a different month?

Tom
Tom Schreiner is offline   Reply With Quote
Old May 18th, 2002, 04:11 AM   #6
TroyBoy
New Member
 
Join Date: May 2002
Posts: 9
Default

I'm trying to increment cell A2 by month and increment cells B4:AF4 by month at the same time... here's the view:

January-02 <- cell A2

1/1/02 1/2/02 1/3/02 etc
B4 C4 D4 etc
Tu We Th etc
B5 C5 D5 etc

So when I increment A2 by one month, cells B4:AF4 and B5:AF5 all increment by one month. It's all part of a scheduling spreadsheet, where the people and the rest of the info stays the same, but the dates and days change.

Thanks for your help

Troy
TroyBoy is offline   Reply With Quote
Old May 18th, 2002, 05:24 AM   #7
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Sorry about the sporadic replies...
I'm at work.

Anyway, play around with the following...


Sub IncrementDate()
'increments the current date in Cell A2
Range("A2") = DateAdd("m", 1, Range("A2"))
'uses the above date with the first day of the month
'forced into Cell B4
Range("B4") = Month(Range("A2")) & "/01/" & _
Year(Range("A2"))
'places a formula in C4 which adds one day to
'Cell C4's value
Range("C4").Formula = "=B4+1"
'fills the formula across to AF4
Range("C4:AF4").FillRight
End Sub




Tom
Tom Schreiner is offline   Reply With Quote
Old May 18th, 2002, 07:16 AM   #8
TroyBoy
New Member
 
Join Date: May 2002
Posts: 9
Default

Thanks Tom, I think that did it just dandy

I plugged it into a spinner control - modified it to work in both directions, and it's outstanding!

BTW Just got off work myself... time for some shut eye. Thanks again for your outstanding help

Troy
TroyBoy is offline   Reply With Quote
Old May 19th, 2002, 07:05 AM   #9
TroyBoy
New Member
 
Join Date: May 2002
Posts: 9
Default

LOL... It ran great until I e-mailed it to myself at home... Home.Minerva is running Excel 2000 with the updates, Work.PieceOfCrap is running Excel 97. Anyways, I sent it home, opened an played with it a bit, everything was cool, then I sent it back to me at work... Now I'm getting a run time Error #1004 FillRight Method of Range class failed. Pretty weird. I'm thinking it's an Excel thing... either that, or I should sell the computer and buy a yo-yo.

Peace!

Troy
TroyBoy is offline   Reply With Quote
Old May 19th, 2002, 07:19 AM   #10
sykes
Board Regular
 
sykes's Avatar
 
Join Date: May 2002
Location: Cornwall,England
Posts: 1,273
Default

Hi Troyboy
I've been using dates quite a bit recently, and think that the EDATE function may solve your problem quite easily.
I'm running 0ffice 2k, and you have to have the Analysis tool pack addin checked.

If you want to increase A2 by 6 months, into A3, just enter into A3 =EDATE(A2,6)and Bob's your uncle.

If you want to increase A2 by 6 months and one day, into A3, just enter into A3 =EDATE(A2,6)+1 and Bob's your auntie.

You'll have to custom format the cells appropriately of course.

Hope this isn't too simple, and that I've completely misread the complexity of the problem. I am after all only a "new boy" to the board.

Kindest

Sykes



[ This Message was edited by: sykes on 2002-05-19 13:00 ]
sykes is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 04:43 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes