Help with If function in vba

laxminarayana

Board Regular
Joined
Nov 16, 2013
Messages
56
Hi,

In the 5th line of the following code marked with red, i am trying to copy date from a cell.
How to do this?

Sub autotext()
If Worksheets("Sheet1").Range("B1").Value = Worksheets("Sheet1").Range("B3").Value Then
Worksheets("Sheet2").Activate
Range("D1").Select
Range("D1").Value = "This is the Date **\**\**** "
Else
Worksheets("Sheet2").Activate
Range("D1").Select
Range("D1").Value = "N/A"
End If
End Sub

Thank you
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
It looks to me like the you are trying to place a sentence with a date in a cell, not copy the date from a cell.
Where is the data that you are trying to place in this cell coming from?
 
Upvote 0
It looks to me like the you are trying to place a sentence with a date in a cell, not copy the date from a cell.
Where is the data that you are trying to place in this cell coming from?


Thank you for replying

Sheet1 "B1" contains a Date, i want that to be inserted in the sentence.

That is if in sheet1 B1=B3 (both cells contain Dates) then sentence should be placed in D1 of sheet2 with date of Sheet1 B1.
 
Upvote 0
Try

Range("D1").Value = "This is the Date " & Format(Worksheets("Sheet1").Range("B1"),"mm\dd\yyyy")

Adjust the date format to your liking.
 
Upvote 0
Try

Range("D1").Value = "This is the Date " & Format(Worksheets("Sheet1").Range("B1"),"mm\dd\yyyy")

Adjust the date format to your liking.

wow that worked. Thank you very much

Can you please tell how to insert date that is one day after the date in cell B1
 
Upvote 0
You're welcome..

To add 1 day, try

Range("D1").Value = "This is the Date " & Format(Worksheets("Sheet1").Range("B1")+1,"mm\dd\yyyy")
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top