I have my data like so, in A1:A3 in excel.
stack',' over',' flow','
Is there anyway to combine this into one cell?
I've tried copy and paste to word and notepad ++ but they give me these with space gaps between them. My idea is to use these in a SQL query.
Other questions on here regard VBA for multiple rows.
Concatenante does not work as in reality I use a larger range then A1:A3
If you have CONCAT() function:
=CONCAT(A1:A3)
IF not:
= A1 & A2 & A3
If you do not have CONCAT, put this UDF in a module and use the formula as described above:
Function CONCAT(rng As Range)
Dim rngArr As Variant
Dim i As Long, j as long
rngArr = rng.Value
For i = LBound(rngArr, 1) To UBound(rngArr, 1)
For j = LBound(rngArr, 2) To UBound(rngArr, 2)
CONCAT = CONCAT & rngArr(i, j)
Next j
Next i
End Function
Related
I am using below mentioned formula to filter out the unwanted text from a Cell. I would like to use this formula via VBA, i have tried some method that includes Sub Formula_Property and Recording Macro but not successful.
The formula is mentioned below:
=LEFT(A3,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A3 & "1234567890"))-1)
The Main data is available in Sheet1 ColumnA2:A5000 and I would like the filtered text (Result) in Sheet3 column B2:B5000.
Is there anyway i can automate this using VBA, that would be helpful for me much.
Thank you
Parse Left of First Digit
Sub ParseLeftOfDigit()
Dim Data(): Data = Sheet1.Range("A2:A5000").Value
Dim r As Long, n As Long, rStr As String
For r = 1 To UBound(Data, 1)
rStr = CStr(Data(r, 1))
For n = 1 To Len(rStr)
If Mid(rStr, n, 1) Like "#" Then
Data(r, 1) = Mid(rStr, 1, n - 1)
Exit For
End If
Next n
Next r
Sheet3.Range("B2:B5000").Value = Data
End Sub
This macro will apply that formula to the range you wish.
Sub Filter_Text_Formula()
Sheets("Sheet3").Range("B2:B5000").FormulaR1C1 = "=LEFT(Sheet1!RC[-1],MIN(FIND({1,2,3,4,5,6,7,8,9,0},Sheet1!RC[-1] & ""1234567890""))-1)"
End Sub
Hello I need to advice some formulas on my problem:
How can I combine two, three or more columns into single one column?
And if in columns are "empty" cells I want to skip these cells inside of that single one column.
But be aware! This is the problem. All columns are contains another formulas. So these "empty" cells are in fact contains my another formulas with result ="".
Here is example of what I want to get - in column E:
EDIT:
New functions like TOCOL are not available in my Microsoft Office 365 MSO: 16.0.14326.21092 (32 bit).
You can use:
Formula in E2:
=TOCOL(IF(A2:C10="",NA(),A2:C10),3,1)
Note that just =TOCOL(A2:C10,3,1) is not going to cut it if these cells hold an empty string "".
If your data is not very huge use:
=FILTERXML("<t><s>"&TEXTJOIN("</s><s>",1,TRANSPOSE(A2:C10))&"</s></t>","//s")
With VBA:
Option Explicit
Sub To_Col()
Dim lngR As Long, lngC As Long, varV, lngRow As Long, lngCol As Long
varV = [A2:C10]
With ActiveCell
lngRow = .Row
lngCol = .Column
End With
For lngC = 1 To UBound(varV, 2)
For lngR = 1 To UBound(varV)
If varV(lngR, lngC) <> "" Then
Cells(lngRow, lngCol).Value = varV(lngR, lngC)
lngRow = lngRow + 1
End If
Next lngR
Next lngC
End Sub
place in E2 and launch macro, change [A2:C10] with your real range
Assume to have the following Excel table
I'm trying to write a Macro in VBA which scans the cells in the routing column and spreads the substrings into the other columns. So this should be the final result
Potentially if the algorithm finds n substrings in the main string under the column Rtg it should fill n columns with the substrings.
Can you guys help me?
Thanks in advance
We can parse using the dash character:
Sub dural()
Dim i As Long, N As Long
N = Cells(Rows.Count, "B").End(xlUp).Row
For i = 2 To N
arr = Split(Cells(i, 2).Value, "-")
Cells(i, 2).Offset(0, 1).Resize(1, UBound(arr) + 1) = arr
Next i
End Sub
EDIT#1:
The code will err if it encounters an empty cell prematurely. To avoid this use:
Sub dural()
Dim i As Long, N As Long
N = Cells(Rows.Count, "B").End(xlUp).Row
For i = 2 To N
v = Cells(i, 2).Value
If v <> "" Then
arr = Split(v, "-")
Cells(i, 3).Resize(1, UBound(arr) + 1) = arr
End If
Next i
End Sub
As outlined here, you can use Text to Columns:
Select the cell or column that contains the text you want to split.
Select Data > Text to Columns.
In the Convert Text to Columns Wizard, select Delimited > Next.
Select the Delimiters for your data. You'd want to put a - in the "Other" area.
Select Next.
Select the Column data format or use what Excel chose for you.
Select the Destination, which is where you want the split data to
appear on your worksheet.
Select Finish.
Here is a simple sub for operating on the current active cell.
Sub splitCell()
Dim cellSplit As Variant
Dim nextColumn As Long
nextColumn = 1
cellSplit = Split(ActiveCell.Value2, "-")
For Each Item In cellSplit
ActiveCell.Offset(0, nextColumn).Value2 = Item
nextColumn = nextColumn + 1
Next
End Sub
None of the other solutions appear to deal with leading hyphens correctly.
This should deal with leading/trailing/double hyphens on the currently selected cells within one column. The caveat is that the individual substrings should not contain spaces.
Sub splitHyphens()
Dim i As Long, sel As Range, vals As Variant
For Each sel In Selection
vals = Split(Application.Trim(Replace(sel.Value, "-", Space(1))), Space(1))
sel.Offset(0, 1).Resize(1, UBound(vals) + 1) = vals
Next sel
End Sub
I want to apply a filter on a set of data, after that I would like to fill a range of data into a range of cells. But now if this will be done, the last two rows are getting the values of the first cell.
-74.4398
-74.2028
-69.8689
-73.1567
-80.1015
-75.822
-75.0529
-75.9859
-79.2546
-72.8093
-71.6604
This is the list of numbers in cell B3 to B13. One button with the following VBA code behind:
Private Sub CommandButton1_Click()
Dim arr() As Variant
Dim i As Integer
ReDim arr(1 To 11, 1 To 1)
arr(1, 1) = "Hallo"
arr(2, 1) = "Welt"
arr(3, 1) = "Holla"
arr(4, 1) = "verdugón"
arr(5, 1) = "Hello"
arr(6, 1) = "World"
arr(7, 1) = "Ciao"
arr(8, 1) = "mondo"
arr(9, 1) = "Salut"
arr(10, 1) = "terre"
arr(11, 1) = "Final"
Worksheets("Sheet1").Range("C3:C13").Value = arr
End Sub
If you now set a filter on cell C2 to just show all values greater than -75 you will get a list like that:
-74.4398
-74.2028
-69.8689
-73.1567
-72.8093
-71.6604
If you now press the button so that VBA code will be executed, you will see that the content in cell C12 and C13 has the same value as in cell C3.
Why does it happened, why does it not fill up the cells with the right content ?
I expected that cell C12 will be 'terre' and C13 'Final'.
Is that an excel issue / bug ?
EDIT: It is more worst as I thought, I used now a different value for the filter -74 and not only the last entries are incorrect, all are incorrect:
I believe it is really a bug and it seems it has been there for some time - see this LINK.
At first glance I would say it's not a bug, and it's moreso the nature of arrays, however I could be completely wrong. If you were looking for a working solution, I went ahead and created this:
Sub Button2_Click()
Dim sht As Worksheet, lastrow As Integer, arr() As Variant
Set sht = ThisWorkbook.Worksheets("Sheet1")
lastrow = sht.Cells(sht.Rows.Count, "B").End(xlUp).Row
arr = Array("Hallo", "Welt", "Holla", "verdugón", "Hello", "World", "Ciao", "mondo", "Salut", "terre", "Final")
For i = 3 To lastrow
Range("C" & i).Value = arr(i - 3)
Next i
End Sub
I want to use more than 30 arguments in sum formula for excel, I am using below formula:-
=SUM(IF(AND(ISNUMBER($F$73),ISNUMBER($J$73)),PRODUCT($F$73,$J$73/100),0),IF(AND(ISNUMBER($G$74),ISNUMBER($J$74)),PRODUCT($G$74,$J$74),0))
Above formula will work fine for 30 argumnets, but for more than 30 argumemts excel will return error(#VALUE)
You could batch smaller groups into sub-SUMs like this:
=SUM(SUM(1,2), SUM(3,4),...).
This version will be shorter, you can add as many as you want, only limit will be maximum formula length
=(COUNT(F73,J73)=2)*(F73*J73/100)+(COUNT(G74,J74)=2)*(G74*J74/100)
Perhaps you could save further characters in your formula like this:
=(N(F73)*N(J73)+N(G74)*N(J74))/100
which could be extended much further, but for clarity, I'd suggest writing a custom UDF:
=SPRange((F73,G74),(J73,J74))%
SPRange would work like SUMPRODUCT but operates on multiple ranges:
Function SPRange(Range1 As Range, Range2 As Range) As Double
Dim i As Long, n As Long, rng As Range, Arr() As Double
n = Range1.Count
ReDim Arr(1 To n) As Double
i = 1
For Each rng In Range1
If IsNumeric(rng.Value2) Then Arr(i) = rng.Value2
i = i + 1
Next rng
i = 1
SPRange = 0
For Each rng In Range2
If IsNumeric(rng.Value2) Then SPRange = SPRange + Arr(i) * rng.Value2
i = i + 1
Next rng
End Function
If you want to extend to many ranges you can define names through code:
names.Add "Range1",Range("f73,g74")
names.Add "Range2",Range("j73,j74")
which allows for over 1000 cells in my tests. Then just enter the formula as:
=SPRange(Range1,Range2)%