Insert additional data into cell if date already exists.

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, I successfully am able to use the VBA below to insert text in Column D based on date in Column B. I want to have it be added if there is text already in Column D, naturally with a space. I don't want the inserted text to overwrite what is already in the cell. Thank you,

VBA Code:
Sub COVID()
    Dim lr As Long
    Dim i As Long
    Dim wsAct As Worksheet
  
  Set wsAct = ActiveSheet
  Application.ScreenUpdating = False
  With Sheets("Outbound FIDS")
    .Activate
    lr = Range("C" & Rows.Count).End(xlUp).Row
    
    For i = 1 To lr
        If Range("D" & i).Value = "" And Range("B" & i).Value <> "" Then
            Range("D" & i).Value = "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL"

        End If
    Next i
    End With
wsAct.Activate
  Application.ScreenUpdating = True
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Change this line:
Range("D" & i).Value = "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL"
to this:
Range("D" & i).Value = "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL " & Range("B" & i).Value

Note the space after MANUAL.
 
Upvote 0
Try this:

VBA Code:
    If Range("B" & i).Value <> "" Then
        If Range("D" & i).Value = "" Then
            Range("D" & i).Value = "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL"
        Else
            Range("D" & i).Value = Range("D" & i).Value & " " & Range("B" & i).Value
        End If
    End If
 
Upvote 0
Change this line:
Range("D" & i).Value = "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL"
to this:
Range("D" & i).Value = "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL " & Range("B" & i).Value

Note the space after MANUAL.
Hello I tried what you suggested and it moved the data from Column B to Column D, I want the statement "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL" to put into Column D. This is based on if there is data in Column B. If there is data already in Column D I would need the statement place after the data already in Column D. Thank you.
 
Upvote 0
Then try this:

VBA Code:
    If Range("B" & i).Value <> "" Then
        If Range("D" & i).Value = "" Then
            Range("D" & i).Value = "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL"
        Else
            Range("D" & i).Value = Range("D" & i).Value & " " & "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL"
        End If
    End If
 
Upvote 0
Try this:

VBA Code:
    If Range("B" & i).Value <> "" Then
        If Range("D" & i).Value = "" Then
            Range("D" & i).Value = "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL"
        Else
            Range("D" & i).Value = Range("D" & i).Value & " " & Range("B" & i).Value
        End If
    End If
Thank you for getting back. Your code had the same result as mine with suggestions by the other person in this thread. What happens if there is a time in Column B then the statement will go into Column D. If there is a data already in Column D then add the statement after the preexisting statement. Note this is for a schedule for three days which means the word "Remark" is also in a cell in Column D three time, so that word can be ignored. It does not share a row with a time, so I don't think that will make a difference. Thank you.
 
Upvote 0
Then try this:

VBA Code:
    If Range("B" & i).Value <> "" Then
        If Range("D" & i).Value = "" Then
            Range("D" & i).Value = "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL"
        Else
            Range("D" & i).Value = Range("D" & i).Value & " " & "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL"
        End If
    End If
That is a lot better, I am hoping I can get it to ignore the REMARKS cell. Everything else is spot on. Thank you.
 

Attachments

  • remarks.JPG
    remarks.JPG
    105.5 KB · Views: 8
Upvote 0
Then try this:

VBA Code:
    If Range("B" & i).Value <> "" Then
        If Range("D" & i).Value = "" Then
            Range("D" & i).Value = "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL"
        Else
            Range("D" & i).Value = Range("D" & i).Value & " " & "REFER TO DEPARTMENT OF STATE TRAVEL MANUAL"
        End If
    End If
Hello again, I'm finally nearly finished with this project, so I'm trying to get the code you provided to ignore cells in Column D to ignore cells containing "REMARKS". Thank you in advance.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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