Adding a Cell Value to the Another Cell based on Conditon

madhuchelliah

Board Regular
Joined
Nov 22, 2017
Messages
226
Office Version
  1. 2019
Platform
  1. Windows
Hello Folks, i have data in cell D4. Data is consists of alpha, numeric and symbols. I want to find the single alpha character in the cell D4 and i have to insert the alpha character from C4 in front of that without space. Alpha character is always single but mingled with numeric and symbols. If already alpha character is present with 2 alphas together then no need to add. Please go through the example for better clarity. Data shown in the row 4 is actual data. Row 5 is expected result. wherever single alpha is available alpha value from C4 is added before that. Where 2 alpha(BA) already exist C4 value should not be added. Thank you.

Book1
CD
4A2154-255 254B, 5545E, D454-D444 258BA454
52154-255 254AB, 5545AE, AD454-AD444 258BA455
Sheet1
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi Madhuchelliah,

This works but might not be the best streamlined code as I am not an expert:

VBA Code:
Sub LoopThroughString()

    Dim outputString, chrString, chrString2, TempString As String
    Dim strPos, strPos2 As Integer
    
    inString = ActiveSheet.Range("E4").Value
    
    For strPos = 1 To Len(inString)
        strPos2 = strPos + 1
        chrString = Mid(inString, strPos, 1)
        chrString2 = Mid(inString, strPos2, 1)
        If chrString Like "[a-zA-Z]" Then
        
            If Not chrString2 Like "[a-zA-Z]" Then
        
                TempString = outputString & ActiveSheet.Range("D4").Value & chrString & chrString2
                outputString = TempString
                            
            End If
                
            If chrString2 Like "[a-zA-Z]" Then

                TempString = chrString & chrString2
                outputString = outputString + TempString
                
            End If
            
            strPos = strPos + 1
            strPos2 = strPos2 + 1
            
        End If
        
        If Not chrString Like "[a-zA-Z]" Then
        
            outputString = outputString + chrString
        
        End If
                        
    Next
    
    ActiveSheet.Range("E6").Value = outputString
    MsgBox outputString

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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