VBA inserting Text in addition to preexisting text in a cell.

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
774
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, I have a VBA which had changed slightly, but now I'm running into an issue where it will not add text to a cell if data already exists. The formula I'm using is:
VBA Code:
Sub Depositioner()
  Dim i As Long
  For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
    If Left(Cells(i, 1).Value, 2) Like "*V" Then
      
     If ActiveSheet.Range("F" & i) = "" Then
 ActiveSheet.Range("F" & i) = "DEPOSITIONER"
      Else
ActiveSheet.Range("F" & i) = ActiveSheet.Range("F" & i) & "/DEPOSITIONER"
    End If
    End Select
Next i

End Sub

The bottom portion beginning with "If ActiveSheet" worked properly if I used the syntax "CASE" in the first portion of the VBA, but now I am using a wildcard "*V" I am getting an error on the "End Select" Portion of the VBA. Any assistance would be wonderful.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi. Maybe this could work.
VBA Code:
Sub Depositioner()
 Dim i As Long
  For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
   If Left(Cells(i, 1).Value, 2) Like "*V" Then
    If ActiveSheet.Range("F" & i) = "" Then
     ActiveSheet.Range("F" & i) = "DEPOSITIONER"
    Else
     ActiveSheet.Range("F" & i) = ActiveSheet.Range("F" & i) & "/DEPOSITIONER"
    End If
   End If
  Next i
End Sub
 
Upvote 0
Solution
Hi

So just checking. Is my understanding correct?

If column A 2nd letter is a V or a v then
check to see if F is blank
if blank answer is "DEPOSITIONER"
if not blank is current text and "/DEPOSITIONER"

if so try this

dave

VBA Code:
Sub Depositioner()
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
    If Left(Range("A" & i), 2) Like "V" Then
        If Range("F" & i) = "" Then
            Range("F" & i) = "DEPOSITIONER"
        Else
            Range("F" & i) = Range("F" & i) & "/DEPOSITIONER"
        End If
    End If
Next i
End Sub
 
Upvote 0
Thank you very much it worked perfectly.
 
Upvote 0
If you are interested, you could process all the rows at once instead of looping through one at a time.

VBA Code:
Sub Depositioner_v2()
  With Range("F1:F" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = Evaluate(Replace(Replace("if(exact(mid(%,2,1),""V""),if(#="""","""",#&""/"")&""DEPOSITIONER"",if(#="""","""",#))", "%", .Offset(, -5).Address), "#", .Address))
  End With
End Sub
 
Upvote 0
Hi Peter

so it would, missed the *
 
Upvote 0

Forum statistics

Threads
1,221,525
Messages
6,160,329
Members
451,637
Latest member
hvp2262

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