Help remove unwanted semi colons after last value in a string

DaleKeel

Board Regular
Joined
Sep 11, 2019
Messages
56
Office Version
  1. 2013
Platform
  1. Windows
First User Clicks button (Peace Out) to clear all data.

Sub Delete_Entries()

' Delete Macro

Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("C2").Select
Selection.ClearContents
End Sub

The User Manually copies data from a source and then pastes Values from source to cell A2...

Sub Paste_Values()
'
' Paste_Values Macro
'

'
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

Then User click Button (Abracadabra) and makes a single string of data. The problem is that it leaves unwanted semi colons at the end.
I do not know how to get rid of them. Please help. Thanks



Sub vba_concatenate()

Dim rng As Range
Dim i As String
Dim SourceRange As Range

Set SourceRange = Range("A2:A100")

For Each rng In SourceRange
i = i & rng & "; "
Next rng
Range("c2").Value = Trim(i)

End Sub
 

Attachments

  • Untitled-1.jpg
    Untitled-1.jpg
    30.9 KB · Views: 6

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
VBA Code:
rng = Left(rng, Len(rng) - 1)
 
Upvote 0
Try this:

VBA Code:
Sub vba_concatenate()
  Dim rng As Range
  Dim i As String
  Dim SourceRange As Range
 
  Set SourceRange = Range("A2", Range("A" & Rows.Count).End(3))
 
  For Each rng In SourceRange
    If rng.Value <> "" Then i = i & rng.Value & "; "
  Next rng
   
  If i <> "" Then
    Range("c2").Value = Trim(Left(i, Len(i) - 2))
  End If
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Last edited:
Upvote 0
Solution
Sub vba_concatenate() Dim rng As Range Dim i As String Dim SourceRange As Range Set SourceRange = Range("A2", Range("A" & Rows.Count).End(3)) For Each rng In SourceRange If rng.Value <> "" Then i = i & rng.Value & "; " Next rng If i <> "" Then Range("c2").Value = Trim(Left(i, Len(i) - 2)) End If End Sub
This WORKED. Thank you VERY much for your time and knowledge.
 
Upvote 0
In future please mark the post that contains the solution, not you post saying it works. Thanks
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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