Padding spaces in excel 2016 - excel-2016

Is there a way to pad spaces in excel 2016?
I have two columns, I want to concatenate the two fields with spaces between the values align.
My results:
id last NewColumn
1 Smith 1 = Smith
2 CoppHeadlager 2 = CoppHeadlager
My expect results. The spacing between the columns align, how can I do this?
id last New column
1 Smith 1 = Smith
2 CoppHeadlager 2 = CoppHeadlager

Try this:
= text(A:A,"00") & " = " & trim(B:B)

Related

Set the value from another sheet. With a test of condition. Excel

I have a table with two sheets. On the first (1) the name is written, on the second (2) Imin and numerical meaning are written, the same name can be written several times. There are also names that are not present on the sheet (1).
Sheet 1.
A
Column A
Column B
Vova--
Ben
Sheet 2.
Column A
Column B
Ben +
2
Timmy
1
Ben T
4
Vova
6
How to put in the first sheet the sum of the values from the sheet (2)
I tried:
=IF(ColA2 = $Sheet2 ColA2; $Sheet2 ColB2)
=VLOOKUP(A1;$Sheet2.B2:B4;2)
=SUMIF($'Sheet2'A1:A4;A1;$'Sheet2'ColB1:ColB4)
Not work
Does not summarize the value
Looking for accurate coincidences
Names can end in different ways ...
Ben = Ben T
Required:
Column A
Column B
Vova--
6
Ben
3
Need help please.
I found an answer. I need to use LEFTB
=SUMIF($'Sheet2'A1:A4;LEFTB(A1;4)&"*";$'Sheet2'ColB1:ColB4)
or
=SUMPRODUCT((LEFTB($Sheet2!$A$1:$A$4;3)=A2)*$Sheet2!B2:B5)

FormulaArray keeps changing to relative references

I'm trying to enter a formula in a sheet using VBA (for later use in Excel Solver). It worked fine until this morning.
For u = 1 To Row2
Sheets("Testa").Cells(u + 1, 14).FormulaArray = "=SUM(IF(B2:B2000=" & CStr(u) & ",F2:H2000,0))"
Next
For v = 1 To Row
Sheets("Testa").Cells(v + 1, 18).FormulaArray = "=SUM(IF(A2:A2000=" & CStr(v) & ",F2:H2000,0))"
Next
The first loop gives this as a result in the cell: "=SUM(IF(RC[-12]:R[1998]C[-12]=1,RC[-8]:R[1998]C[-6],0))", changing the absolute references to relative references and not translating the functions to the french equivalent. The second loop works just fine. Column A and B contain a list of numbers (from 1 to Row or Row2) that look like this :
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
I don't know what I'm missing. Any help is welcome !
The range where I was writing the formula was set up as a text range, explaining why it didn't compute the formula. Changing it manually to a standard range solved the problem.

Use V-Lookup to the cell number

So I have been given the task of comparing to worksheets in excel and if there is a match replacing the data from one cell with another, for example, I have 2 columns in 2 excel sheets, ID and name, I want to compare the IDs in sheet 1 with the IDs in sheet two and if it finds a match update the name linked with that ID.
Sheet 1
ID Name
1 Thomas
2 Jerry
Sheet 2
ID Name
3 Spike
1 Tom
So in the example above, I need the code to see that ID 1 is in both sheets and change the name in sheet 1 to match sheet 2, so that it looks like this:
ID Name
1 Tom
2 Jerry
I'm trying to use the Vlookup, which has allowed me to find out if it is existing or not, but then I don't know how to change the cell to match the existing one, here is my code so far:
Range("C2").Select
ActiveCell.Formula = _
"=IF(ISNA(VLOOKUP([#[ID]], 'Sheet2'!A:B,1,FALSE)), ""New"", ""Existing"")"
Do While Len(Range("A" & r).Formula) > 0
If (Range("C" & r).Value = "Existing") Then
Sheets("Sheet2").Range("A" & r & ":B" & r).Copy _
Destination:=Sheets("sheet1").Range("A" & r & ":B" & r)
Else
End If
I need to be able to get the cell number from the Vlookup so that I can use it in the if statement to pull in the correct data. There may be a simpler way to do this, if so I am open to changing everything.
Any help would be much appreciated.
I don't think there is a need of VBA for this task. As the names in "Sheet1" has to be updated by looking into the data in "Sheet2". Following formula can be used to find the updated names (by looking into data from the "Sheet2").
=IFERROR(VLOOKUP(A2,Sheet2!A2:B3,2,FALSE),B2)
IFERROR is used so as to retain the names which were not found in "Sheet2" data. Have a look at following screenshot for the example.
Easiest way is on a third sheet create 3 headings in row A: ID, Name and Source. Copy your data from sheet 1 into the first two columns and fill the third column with the text sheet 1. Do the same for sheet 2 but paste it below your sheet 1 data. You should end up with something like this:
ID Name Source
1 Thomas Sheet 1
2 Jerry Sheet 1
3 Spike Sheet 2
1 Tom Sheet 2
Then just create a pivot table from this data with source as the column, name as the row and a count of name for the data. It should look something like this:
Name Sheet 1 Sheet 2 Total
Thomas 1 0 1
Jerry 1 0 1
Spike 0 1 1
Tom 0 1 1
You can then sort on the Total column to find the duplicates which will have a total of two.
One other advantage of using this method is that it is quite easy to expand it to compare three or more lists.

How to replace all spaces with new lines?

I have a table that contains spaces in its headers
First Name Last Name Average Level Degree
_________________________________________________
Mike Lowel 25
Stan Wilson 35
Papa Peterson 15
I need it to look like this
First Last Average
Name Name Level
Degree
_____________________________________________
Mike Lowel 25
Stan Wilson 35
Papa Peterson 15
Here is what I tried
Sub test()
myString = ThisWorkbook.Worksheets(1).Range("a1").Value
ThisWorkbook.Worksheets(1).Range("a1").Value = Replace(myString, " ", CHAR(10))
ThisWorkbook.Worksheets(1).Range("a1").WrapText = True
ThisWorkbook.Worksheets(1).Range("a1").EntireRow.AutoFit
myString = ThisWorkbook.Worksheets(1).Range("b1").Value
ThisWorkbook.Worksheets(1).Range("b1").Value = Replace(myString, " ", CHAR(10))
ThisWorkbook.Worksheets(1).Range("b1").WrapText = True
ThisWorkbook.Worksheets(1).Range("b1").EntireRow.AutoFit
End Sub
However, it throws an error. In addition, I am not sure how to loop over all letters. Is there any more efficient way. I need those headers to look nice: I need to get the same effect as if I click Alt+Enter. Each word should appear on a separate line
You can do this with one line of code:
Range("A1:C1").Replace " ",vblf
In the range it replaces all spaces with a VB Line Feed (Return)

Creating separate line entries for multi-value fields

I have a table with a list of items. Essentially it's an export from an issue tracking tool. One of the columns of that table contains comma-separated values. I am looking for a way to create separate entries for the individual values of multi-value entries.
Example: (this is a simplified example, the real case contains around a dozen columns)
Source data:
ID | Title | Areas Affected |
1 | Issue title A | Area X, Area Y |
2 | Issue title B | Area Y, Area Z |
3 | Issue title C | Area X, Area Z |
What I am trying to get to:
ID | Title | Areas Affected |
1 | Issue title A | Area X |
1 | Issue title A | Area Y |
2 | Issue title B | Area Y |
2 | Issue title B | Area Z |
3 | Issue title C | Area X |
3 | Issue title C | Area Z |
It is OK that there are now duplicate entries for IDs and Titles?
Is there a formula, macro, or VBA script to achieve this?
You need to split rows on that column using the comma as a separator. In VBA you have the Split() function that you can use to return an array. For the first element just put it back in the cell where the list was. For the others, insert a new line for each element in the array (meaning you can have n elements in that comma-separated list), copy the entire row on that new line and put the i-th value in there.
After some reading/going through sample code, here's the answer if anyone needs. This is the actual working code, which doesn't fit 1:1 the examples I posted in the question.
Sub DataLobs()
Application.ScreenUpdating = False 'Nice to have to increase the script speed.
Dim wsSrc As Worksheet
Dim wsDst As Worksheet
Dim curRowSrc As Integer
Dim curRowDst As Integer
Dim ttlRows As Integer
Dim splitLob() As String
' Setting initial values to start rows in source and destination
' tables, as well as the total number of rows
curRowSrc = 5
curRowDst = 5
ttlRows = 10000
Set wsSrc = Worksheets("Source") 'whatever you worksheet is
Set wsDst = Worksheets("Destination") 'or whatever your worksheet is called
wsDst.Range("A5:F" & ttlRows).Clear
' Goes through column D in the source table
' and copies rows where the D cell is not blank
' into the destination table
For curRowSrc = 5 To ttlRows
If wsSrc.Range("D" & curRowSrc).Value <> "" Then ' There are some blank cells in the source table, so we are eliminating them.
' Split the cell value against the comma
splitLob = Split(wsSrc.Range("D" & curRowSrc).Value, ", ") 'THIS IS WHERE #AlexandreP.Levasseur's HINT COMES INTO PLAY!
For i = LBound(splitLob) To UBound(splitLob)
wsDst.Range("A" & curRowDst).Value = splitLob(i)
wsDst.Range("B" & curRowDst).Value = wsSrc.Range("A" & curRowSrc)
wsDst.Range("C" & curRowDst).Value = wsSrc.Range("C" & curRowSrc)
wsDst.Range("D" & curRowDst).Value = wsSrc.Range("AC" & curRowSrc)
wsDst.Range("E" & curRowDst).Value = wsSrc.Range("AE" & curRowSrc)
wsDst.Range("F" & curRowDst).Value = wsSrc.Range("AD" & curRowSrc)
curRowDst = curRowDst + 1
Next
End If
Next curRowSrc
End Sub