Add data in cell without overwriting preexisting data.

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings. I can easily add text to a cell, but I have different macros in my project which potentially asks data to be placed in the same cell. I believe I will need something like an Else statement. The following macro works great on a blank cell. However, I would like it to have a // following the existing data if the cell is not empty. Thank You

VBA Code:
Sub Step_Truck()
    Dim i As Long
    For i = 3 To ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
    Select Case ActiveSheet.Cells(i, 3).Value
    Case "B757", "B75720", "B7772E", "B7673E", "MD011F", "B76720", "B76730", "A400M"
ActiveSheet.Range("E" & i) = "EXPECT TO STEP"
End Select
Next i
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
VBA Code:
    Select Case ActiveSheet.Cells(i, 3).Value
        Case "B757", "B75720", "B7772E", "B7673E", "MD011F", "B76720", "B76730", "A400M"
           '========================
           '   Check whether the cell is blank
           '========================
            IF Trim(ActiveSheet.Range("E" & i) = "" THEN  
                '==========
                '    Is blank
                '==========            
                ActiveSheet.Range("E" & i) = "EXPECT TO STEP"
            ELSE
                '============
                '    Is not blank
                '============  
                ActiveSheet.Range("E" & i) = ActiveSheet.Range("E" & i) & " // EXPECT TO STEP"
            END IF
    End Select
 
Upvote 0
Solution
VBA Code:
    Select Case ActiveSheet.Cells(i, 3).Value
        Case "B757", "B75720", "B7772E", "B7673E", "MD011F", "B76720", "B76730", "A400M"
           '========================
           '   Check whether the cell is blank
           '========================
            IF Trim(ActiveSheet.Range("E" & i) = "" THEN 
                '==========
                '    Is blank
                '==========           
                ActiveSheet.Range("E" & i) = "EXPECT TO STEP"
            ELSE
                '============
                '    Is not blank
                '============ 
                ActiveSheet.Range("E" & i) = ActiveSheet.Range("E" & i) & " // EXPECT TO STEP"
            END IF
    End Select
It is wonderful thank you so much!!
 
Upvote 0

Forum statistics

Threads
1,215,267
Messages
6,123,964
Members
449,137
Latest member
yeti1016

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