For example i have two cells
A1: =1/2
A2: /abc
I want to replace / char in second cell with something else without changing first cell which contains formula. Final result should be like this
A1: = 1/2
A2: #abc
Select your cells and run:
Sub dural()
Dim r As Range
For Each r In Selection
If Not r.HasFormula Then
r = Replace(r.Text, "/", "#")
End If
Next r
End Sub
Replace /a with #a as shown below:
You can use a formula creating a new column: Let's say that the value is in cell A1, you could put this in the cell b1:
=IF(ISFORMULA(A1),A1,SUBSTITUTE(A1,"/",""))
Related
I have a column that contains data for eg: 6B31-21045M22-AA
I'm trying to split the data before and after '-'. Like
A B C D
6B31-21045M22-AA 6B31 21045M22 AA
I tried
=LEFT(A2, SEARCH(“-”,A2)-1) and =Right(A2, SEARCH(“-”,A2)-1)
but if "-" occurs more than once then how do i split the 6B31-21045M22-AA or
6B31-21045M22-AA-SWQ
You don't need a formula or a VBA script. You can use Text to Columns function. Simply select the column with your data and use Text to Columns button on the Data panel. Then in a Wizard select Delimiter and set a "-" symbol as a delimiter.
With data in A1, in B1 enter:
=TRIM(MID(SUBSTITUTE($A1,"-",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
and copy across:
(this can also be done with VBA)
EDIT#1:
Using VBA, select the cell you wish to process and run this:
Sub Splitter()
Dim ary, i As Long, a
With ActiveCell
ary = Split(.Value, "-")
i = 1
For Each a In ary
.Offset(0, i).Value = a
i = i + 1
Next a
End With
End Sub
I have a spreadsheet with one hundred rows. I have one column with a value in each cell.
For Example:
ABC
TRE
TED
CAR
I want an output that has all the values in one cell separated by a semicolon.
Any idea how to do this? I am new in Excel.
Output all in a single cell:
ABC; TRE; TED; CAR;
If your inputs are in cells A1, B1, C1 and D1 and your output formula for instance is E1 then use formula:
=CONCATENATE(A1,";",A2,";",A3,";",A4)
Alternatively (using the cells from the previous answer) you can try:
=A1&";"&B1&";"&C1&";"&D1
I figured it out. If anyone needs it. This writes to the first cell in the B column after it has been stored in the total variable.
Option Explicit
Sub Macro1()
Dim r As Range, cell As Range, mynumber As Long
Set r = Range("A1:A118")
Dim total As String
mynumber = 0
For Each cell In r
mynumber = mynumber + 1
total = total + cell.Value + ";"
Next
Cells(1, 2) = total
End Sub
I'd like to ask you this question:
I have in column B of my Excel worksheet these cells
B1: Ciao / text
B2: stackoverflow / text
B3: =A1+A3 / formula (example)
B4: Fabio / text
I want to select only B1, B2, B4; in other words I want to select ONLY CELLS OF COLUMN B WHICH CONTAIN A TEXT, NOT A FORMULA
Is it possible do that in a code as:
rng = 'I DON'T KNOW'
For Each cella In rng
..
Excel has this function built into SpecialCells, so you can do this:
Set rng = Sheets(2).Range("B1:B4").SpecialCells(xlCellTypeConstants)
Looping through worksheet ranges in Excel is very slow and best avoided
you can use the .HasFormula command in a line written more or less as:
If Not cella.HasFormula Then
In this case you will need to copy/select (or whatever) the cell, otherwise not. Put this in your for loop and you're done!
Columns("B:B").Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Let's supose 'large' excel like this:
A |B
ab |ef
|oo
ut |
|oo
ut |ef
That I need is a new row with a summary of all differents values of each column:
A |B
ab |ef
|oo
ut |
|oo
ut |ef
ab,ut |ef,oo <- new row with the 'summary'
Note: I can copy by hand the formula at end of each column, I only need the formula
Following is a function that can be used to Concatenate unique columns values in a cell
Function UniqueItem(InputRange As Range) As Variant
Dim cl As Range, cUnique As New Collection, cValue As Variant
Application.Volatile
On Error Resume Next
For Each cl In InputRange
If cl.Formula <> "" Then
cUnique.Add cl.Value, CStr(cl.Value)
End If
Next cl
UniqueItem = ""
For i = 1 To cUnique.Count
If UniqueItem = "" Then
UniqueItem = UniqueItem & cUnique(i)
ElseIf UniqueItem <> "" Then
UniqueItem = UniqueItem & ", " & cUnique(i)
End If
Next
On Error GoTo 0
End Function
How to use this function
1. Open excel file
2. Press Alt + F11
3. Create a new module and paste the code in it
4. Go back to the excel file and select the cell you want to have the result
5. Enter formula as =UniqueItem(A1:A5) A1:A5 specifies the range. You can specify any range.
Please find the sample file at the following link: Concatenate_different_columns_values_in_a_cell.xlsm
With some tricks (and an extra column) you can do this the following way.
In column A row 1 through 6, I placed some random text.
In column B I placed the following formulae.
B1: =IF(COUNTIF($A$1:$A1,A1)=1,A1&", ","")
B2: =IF(COUNTIF($A$1:$A2,A2)=1,A2&", ","")
B3: =IF(COUNTIF($A$1:$A3,A3)=1,A3&", ","")
B4: =IF(COUNTIF($A$1:$A4,A4)=1,A4&", ","")
B5: =IF(COUNTIF($A$1:$A5,A5)=1,A5&", ","")
B6: =IF(COUNTIF($A$1:$A6,A6)=1,A6&", ","")
B7: =SUBSTITUTE(B1&B2&B3&B4&B5&B6&",",", ,","")
The idea here is that the search list grows from row 1 to the end and marks any unique value. If the statement in B1 through B6 is true, the value from A is used and a , {space} is added.
In B7 I just concatenate all values, then I add an extra comma at the end.
The substitute removes the last ,{space}, with nothing, effectively making sure the list does not end with a comma.
You can paste the formula for B1 in cell B1 and then just paste the formula down. The relative reference automatically increases the search array.
Understand. One (not so elegant) way is the following... Set C1: = B1, the C2: =B1&B2, then copy C2 all the way down to the end.... On the other hand, I think this might be better served by a VBA solution.
Alternatively, you could use this...
http://mcgimpsey.com/excel/udfs/multicat.html
Regards,
Robert Ilbrink
I want to concatenate a range of cells into one cell, without macros/vbscript.
The formula CONCATENATE() gets individual cells.
Its not that easy, but I end up with a solution that works wonders!
A1: the text to search
B1:BN: The range within the results would go
B5: The delimiter text
=MID($A$1,LEN(CONCAT($B$1:B1))+COUNTA($B$1:B1)*LEN($B$5)+1,
SEARCH(
$B$5,
$A$1,
LEN(
CONCAT($B$1:B1)) + COUNTA($B$1:B1)*LEN($B$5)+1)
-(LEN(CONCAT($B$1:B1))+COUNTA($B$1:B1)*LEN($B$5)+1))
As for now it works perfect. Note that you can use whatever text as delimiter. In my case it was "comma + space".
Where Concat is a simple function that concatenates a range of cells:
Function Concat(myRange As Range) As String
Dim r As Range
Application.Volatile
For Each r In myRange
If Len(r.Text) Then
Concat = Concat & IIf(Concat <> "", "", "") & r.Text
End If
Next
End Function
You can either use CONCATENATE() or & to join cells. There is no range you can grab all at once unless you use a UDF such as MCONCAT.