Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default How to add days in date by macro

Hi all, I have TextBox1 on Sheet1 and in that TextBox1 I have date
like "15/02/2010". I made macro (see below) in which I tried to get a
date in cell A7 of Sheet2 which should be the date of 42 days ahead of
the date in TextBox1. My macro is not working and I am getting error
saying "Run-time error '13': Type mismatch". Please can any friend
help that what i am doing wrong.


Sub dd()
tx = Sheets("Sheet1").TextBox1.Value
With Sheets("Sheet2")
..Range("A7").Value = tx + 42
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default How to add days in date by macro

Try

Sub dd()
tx = Sheets("Sheet1").TextBox1.Text
With Sheets("Sheet2")
..Range("A7").Value = CDate(tx.Text) + 42
End With
End Sub

HTH

Bob

"K" wrote in message
...
Hi all, I have TextBox1 on Sheet1 and in that TextBox1 I have date
like "15/02/2010". I made macro (see below) in which I tried to get a
date in cell A7 of Sheet2 which should be the date of 42 days ahead of
the date in TextBox1. My macro is not working and I am getting error
saying "Run-time error '13': Type mismatch". Please can any friend
help that what i am doing wrong.


Sub dd()
tx = Sheets("Sheet1").TextBox1.Value
With Sheets("Sheet2")
.Range("A7").Value = tx + 42
End With
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default How to add days in date by macro

Hi,

When you get your 'date' from the textbox it's a srtring and you have to
convert it to a date. Try this

Sub dd()
tx = Sheets("Sheet1").TextBox1.Value
Stop
With Sheets("Sheet2")
..Range("A7").Value = DateValue(tx) + 42
End With
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"K" wrote:

Hi all, I have TextBox1 on Sheet1 and in that TextBox1 I have date
like "15/02/2010". I made macro (see below) in which I tried to get a
date in cell A7 of Sheet2 which should be the date of 42 days ahead of
the date in TextBox1. My macro is not working and I am getting error
saying "Run-time error '13': Type mismatch". Please can any friend
help that what i am doing wrong.


Sub dd()
tx = Sheets("Sheet1").TextBox1.Value
With Sheets("Sheet2")
..Range("A7").Value = tx + 42
End With
End Sub
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default How to add days in date by macro

Hmm,

And of course you don't need the STOP command I left in by mistake!!

Sub dd()
tx = Sheets("Sheet1").TextBox1.Value
With Sheets("Sheet2")
..Range("A7").Value = DateValue(tx) + 42
End With
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mike H" wrote:

Hi,

When you get your 'date' from the textbox it's a srtring and you have to
convert it to a date. Try this

Sub dd()
tx = Sheets("Sheet1").TextBox1.Value
Stop
With Sheets("Sheet2")
.Range("A7").Value = DateValue(tx) + 42
End With
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"K" wrote:

Hi all, I have TextBox1 on Sheet1 and in that TextBox1 I have date
like "15/02/2010". I made macro (see below) in which I tried to get a
date in cell A7 of Sheet2 which should be the date of 42 days ahead of
the date in TextBox1. My macro is not working and I am getting error
saying "Run-time error '13': Type mismatch". Please can any friend
help that what i am doing wrong.


Sub dd()
tx = Sheets("Sheet1").TextBox1.Value
With Sheets("Sheet2")
..Range("A7").Value = tx + 42
End With
End Sub
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default How to add days in date by macro

On Feb 15, 11:30*am, Mike H wrote:
Hi,

When you get your 'date' from the textbox it's a srtring and you have to
convert it to a date. Try this

Sub dd()
tx = Sheets("Sheet1").TextBox1.Value
Stop
With Sheets("Sheet2")
.Range("A7").Value = DateValue(tx) + 42
End With
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.



"K" wrote:
Hi all, *I have TextBox1 on Sheet1 and in that TextBox1 I have date
like "15/02/2010". *I made macro (see below) in which I tried to get a
date in cell A7 of Sheet2 which should be the date of 42 days ahead of
the date in TextBox1. *My macro is not working and I am getting error
saying "Run-time error '13': *Type mismatch". *Please can any friend
help that what i am doing wrong.


Sub dd()
tx = Sheets("Sheet1").TextBox1.Value
With Sheets("Sheet2")
..Range("A7").Value = tx + 42
End With
End Sub
.- Hide quoted text -


- Show quoted text -


Thanks guys. it works now
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to pull <=14 Days, <=30 Days, 30 Days from a date column Ken Excel Discussion (Misc queries) 3 October 23rd 09 12:53 AM
Conditional Formatting Dates calculating 10 days and 30 days from a certain date Sioux[_2_] Excel Worksheet Functions 2 October 11th 07 02:04 PM
TWO DATES,150 DAYS APART,NEED ONE DATE TO TURN RED AFTER 150 DAYS 440 Excel Programming 3 September 22nd 06 05:24 PM
Macro to highlight cells that are 5 business days from trade date Jason via OfficeKB.com Excel Programming 4 May 9th 05 08:59 AM
Macro to add 1 or more days to a date Robert Christie[_3_] Excel Programming 9 May 27th 04 08:46 AM


All times are GMT +1. The time now is 03:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"