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?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
G1
Excel Formula:
=if(C1="SUNNY",I1,"")
Conditional formats cannot do this. If you use VBA, please let me know,if column "C" not contains the word "SUNNY",how to deal with column "G"
 
Last edited:
Upvote 0
G1
Excel Formula:
=if(C1="SUNNY",I1,"")
Conditional formats cannot do this. If you use VBA, please let me know,if column "C" not contains the word "SUNNY",how to deal with column "G"
Hi hnsd24_CN .
I guess I will need to use VBA.
If column "C" not contains the word "SUNNY", then do nothing in column "G". Thank you for our help.
 
Upvote 0
Starting with the second row of the worksheet, I think the first row must contain a title
VBA Code:
Sub test()
    Dim i As Integer
    Dim r As Integer
    Dim arr() As Long
    r = Range("C65536").End(xlUp).Row
    ReDim arr(1 To r - 1)
    For i = 2 To r
        If Range("C" & i) = "SUNNY" Then
           arr(i - 1) = Range("I" & i)
        Else
           arr(i - 1) = Range("G" & i)
        End If
    Next
    Range("G2:G" & r) = Application.Transpose(arr)
End Sub
 
Upvote 0
Try this:
VBA Code:
Sub Move_Data()
'Modified  10/27/2020  3:50:33 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "C").End(xlUp).Row

For i = 1 To Lastrow
    If Cells(i, "C").Value = "SUNNY" Then Cells(i, "G").Value = Cells(i, "I").Value: Cells(i, "I").Value = ""
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Starting with the second row of the worksheet, I think the first row must contain a title
VBA Code:
Sub test()
    Dim i As Integer
    Dim r As Integer
    Dim arr() As Long
    r = Range("C65536").End(xlUp).Row
    ReDim arr(1 To r - 1)
    For i = 2 To r
        If Range("C" & i) = "SUNNY" Then
           arr(i - 1) = Range("I" & i)
        Else
           arr(i - 1) = Range("G" & i)
        End If
    Next
    Range("G2:G" & r) = Application.Transpose(arr)
End Sub
Thank you for providing the code. However, I ran into an runtime error 13, type mismatch. Not sure why. Is it because it starts at row 5? I changed the range from C65536 to C1000, for the test.
VBA Code:
   arr(i - 1) = Range("G" & i)
 
Upvote 0
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
 
Upvote 0
Try this:
VBA Code:
Sub Move_Data()
'Modified  10/27/2020  3:50:33 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "C").End(xlUp).Row

For i = 1 To Lastrow
    If Cells(i, "C").Value = "SUNNY" Then Cells(i, "G").Value = Cells(i, "I").Value: Cells(i, "I").Value = ""
Next
Application.ScreenUpdating = True
End Sub

My Aswer Is This - Thank you​

This code worked in moving the entire cell content, but I only want the date. How do I change it to only extract the date (mm/dd/yyyy) at the top of that cell?

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?
 
Upvote 0

My Aswer Is This - Thank you​

This code worked in moving the entire cell content, but I only want the date. How do I change it to only extract the date (mm/dd/yyyy) at the top of that cell?

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?
In your original post you said: I would like to extract the date from column "I"
You never mentioned there was more then just a Date in the cell.
Extracting just the date is not something I can do. There may be 5,000 different variations of how a date might look: Like Susan went to the birthday party which was on Monday. Or Susan went to the party which was on Sunday January 14,2020 or maybe Sunday 4/7/1930. But now maybe someone else on this forum may have a answer.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,215,483
Messages
6,125,063
Members
449,206
Latest member
Healthydogs

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