Conditional Formatting or VBA to extract date?

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
210
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I would like to extract the date from column "I" and place that into column "G", but ONLY IF, column "C" contains the word "SUNNY".
Can I use conditional formatting to perform this?
If not, how would I write this in VBA?
 
Assuming your dates in Column I are really of the full format mm/dd/yyyy and are the first text in the cell, then I think this macro should work...
VBA Code:
Sub NeoSez()
  Dim LastRow As Long
  LastRow = Range("C" & Rows.Count).End(xlUp).Row
  Range("G2:G" & LastRow) = Evaluate(Replace("If(C2:C#=""Sunny"",LEFT(I2:I#,10),IF(G2:G#="""","""",G2:G#))", "#", LastRow))
End Sub
 
Upvote 0
Solution

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
How about
VBA Code:
Sub NeoSez()
   With Range("G2:G" & Range("C" & Rows.Count).End(xlUp).Row)
      .Value = Evaluate(Replace("If(" & .Offset(, -4).Address & "=""Sunny""," & .Offset(, 2).Address & ",if(@="""","""",@))", "@", .Address))
   End With
End Sub
Thank you Fluff, but I couldn't get it to work.
You said:
However, this code would work well for something else. I want to move the cell contents from SHEET2 column T to this SHEET1 column I, based on the value of Column A, which is just a number like 001. 002,etc. How do I modify this script for this?

I would need more details.
Like I want the name of the sheets.
When you say SHEET2 I'm not sure if that means the sheet is named "SHEET2" or if it's Sheet(2)

So please say something like Move from sheet named "Alpha" to sheet named "Bravo"
And when you say "Move" does that me copy to another sheet and delete from original sheet?

And you said:
based on the value of Column A, which is just a number like 001. 002,etc

So are you saying if the number is any number or must it be like "22"

What happens if the cell has "Susan is now 22 years old
And do you mean copy to the first empty cell in column I

Hi My Aswer Is This

That is correct! The names of the sheets are SHEET2 & SHEET1. Yes, I would like to copy the full contents from SHEET2 column T to SHEET1 column I. The contents do not have to be deleted. Sheet 2 will be deleted after copy is completed, as there will be a new Sheet 2 every day.

The value of SHEET1 Column A, has a unique identifier number for every row, such as 001, 002- 000001, 000002, etc... which is also on SHEET2 ColumnF. So the contents will be copied based on this unique identifier number, replacing the current contents in SHEET1 column I .
I hope I provided enough information for you now. Thank you so much for your help.
 
Upvote 0
Assuming your dates in Column I are really of the full format mm/dd/yyyy and are the first text in the cell, then I think this macro should work...
VBA Code:
Sub NeoSez()
  Dim LastRow As Long
  LastRow = Range("C" & Rows.Count).End(xlUp).Row
  Range("G2:G" & LastRow) = Evaluate(Replace("If(C2:C#=""Sunny"",LEFT(I2:I#,10),IF(G2:G#="""","""",G2:G#))", "#", LastRow))
End Sub
Thank you Rick Rothstein!! That worked perfectly.
 
Upvote 0
Thank you Fluff, but I couldn't get it to work.

Hi My Aswer Is This

That is correct! The names of the sheets are SHEET2 & SHEET1. Yes, I would like to copy the full contents from SHEET2 column T to SHEET1 column I. The contents do not have to be deleted. Sheet 2 will be deleted after copy is completed, as there will be a new Sheet 2 every day.

The value of SHEET1 Column A, has a unique identifier number for every row, such as 001, 002- 000001, 000002, etc... which is also on SHEET2 ColumnF. So the contents will be copied based on this unique identifier number, replacing the current contents in SHEET1 column I .
I hope I provided enough information for you now. Thank you so much for your help.
Sorry. But to be honest you need to start a new posting with this question. There are forum rules which state new questions should be posted in a new posting.
I will see your posting there and provide a solution there if I can.
Thanks
 
Upvote 0
Sorry. But to be honest you need to start a new posting with this question. There are forum rules which state new questions should be posted in a new posting.
I will see your posting there and provide a solution there if I can.
Thanks
Agreed. I will do that right now.
 
Upvote 0

Forum statistics

Threads
1,214,865
Messages
6,121,988
Members
449,060
Latest member
mtsheetz

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