I have a database with all the U.S. tariff codes that I need to format.
The numbers appear as:
010129
Whereas I need them to appear as:
0101.29
I have tried to use custom formatting to match the decimals with ####.?? but it does not work.
The database contains 19,423 rows of data; therefore, if there is a better way to format the numbers using VBA, I will gladly take that response as well. Thank you!
Because you have Text rather than Numbers, reformatting is not enough. With your data in A1, in B1 enter:
=LEFT(A1,5) & "." & MID(A1,6,3)
and copy down. For example:
EDIT#1
If the double-quotes do not appear in the data then use:
=LEFT(A1,4) & "." & MID(A1,5,2)
See:
Related
I've been looking for a way to change the placement of a character within a cell with a macro, and have not been able to find exactly what I'm looking for. I've found ways to switch words (such as first name last name), but I need to switch a single character that is attached to the end of a number.
The report that's being filtered in registers negative numbers as:
2.00-
and I'm looking for an easy way to switch it to:
-2.00
as I am dealing with a massive number of records. Is there an easy macro that I can use to do this, or do I need to manually change these? Thanks in advance!
Select column then Text-to-Columns, Fixed width, Next, Advanced, Trailing minus for negative numbers, Ok, Finish.
With data in A1, in B1 enter:
=IF(RIGHT(A1,1)="-",-MID(A1,1,LEN(A1)-1),A1)
Create a new column and insert this formula. Replace A3 with the first cell in question, and then drag it down:
=IF(RIGHT(A3,1) = "-", LEFT(A3, LEN(A3)-1) * -1, A3)
I was hoping that there is a way to conditionally format the column G like columns B & C. Possibly as binary, where the text = 1 and blank = 0? Thanks in advance.
Not exactly know the logic but here is a way to accomplish this with tweaking Custom Number Format. Here is the example and how I do it:
Determine your logic. See what I have in my example. I simply used 0 and 1 because Conditional Formatting works better with numbers.
Right click on the cell on column G, make a rule like [=0]"FAIL";[=1]"OKAY". Values inside [ ] is the condition, and the output string is inside the double quotes " ".
As for the Conditional Formatting, I believe you know what to do. Please let me know if this helps and good luck.
I have pasted text in cell A1 that may look like this:
"Vanguard - Total Market - Composite" or "Vanguard - Total Market - Commingled"
I want to cut off the " - Composite" or " - Commingled" and return the rest in cell B1. Currently I'm using this formula in B1:
=LEFT(A1,FIND(" - Composite",A1)-1)
However, I can't figure out how to look for multiple terms (i.e. Composite or Commingled). Is there a formula that could accomplish this? If not, how could I do it in VBA?
Thanks for the help!
If I understand correctly, you're simply looking to strip everything past the second occurrence of -, i.e. returning the trimmed (extra whitespace removed) text left of the first - character. Adapting this solution to locate the last word in the string, this would be it:
=TRIM(SUBSTITUTE(LEFT(A1,LEN(A1)-LEN(MID(A1,FIND(CHAR(1),SUBSTITUTE(A1,"-",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))))+1,LEN(A1)))),"-","",2))
This formula will work with or without the spaces around the -, and regardless of what follows:
If even spacing is important, you can wrap it with SUBSTITUTE functions:
=SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(LEFT(A1,LEN(A1)-LEN(MID(A1,FIND(CHAR(1),SUBSTITUTE(A1,"-",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))))+1,LEN(A1)))),"-","",2)),"-"," - ")," "," ")
And now you have clean, identically-formatted output for all cases:
I've made this formula that will work with many possibilities as long you fill the possibilities range, not needing to change the formula when there's a new one. Here it is:
=LEFT(A2,FIND(INDIRECT(ADDRESS(SUMPRODUCT((--ISNUMBER(SEARCH(Possibilities,A2)))*ROW(Possibilities)),SUMPRODUCT((--ISNUMBER(SEARCH(Possibilities,A2)))*COLUMN(Possibilities)))),A2)-1)
You can use the SUBSTITUTE function and chain multiple calls:
=SUBSTITUTE(SUBSTITUTE(A1," - Composite", ""), " - Commingled", "")
With any text value, I can individually format each character and then copy that formatting to another cell by iterating over the Range.Characters() Collection.
However, if the cell is a number (even if the numberFormatting displays it as a string e.g. dates) then it does not expose a .Characters() property and, indeed, cannot be selectively formatted digit-by-digit.
Why does Excel display strings using Character objects but not numbers, even when the number is being displayed as a string?
If you want to go around this, you may do the following:
In cell A1 put '123456 with the " ' " sign in front.
Then write
range("A1").Characters(1,3).Font.Bold = true
It would take only the first three numbers, not taking into account the " ' " sign. Thus, the number is kind of displayed as a string, but you can still use it calculations e.g. A1 + 4 would give 123460.
I am a little stuck at the moment. I am working on an array of data and need to find a way to input column numbers into formulas.
-I have used the match function to find the corresponding column number for a value.
ex. "XYZ" matched with Column 3, which is equivalent to C1:Cxxxxxx
-now for inputing the C1:Cxxxxxx into a formula to get data for that particular column, I would like to be able to directly reference the Column 3 part, because I plan on using this workbook in the future and the column needed to run the calculation may or may not be column 3 the next time I use it.
- is there any way to tell excel to use a formula to tell excel which column to use for an equation?
so a little more detail, I have the equation
=AND(Sheet3!$C$1:$C$250000=$A$4,Sheet3!$B$1:$B$250000=$B$4)
instead of specifying to use column C, is there a way to use a formula to tell it to use C?
EDIT: more additional info;
"i am basically running the equivalent of a SQL where statement where foo and bar are true, I want excel to spit out a concatenated list of all baz values where foo and bar are true. ideally i would like it to ONLY return baz values that are true, then I will concat them together separately. the way I got it now, the expression will test every row separately to see if true; if there is 18K rows, there will be 18K separate tests.. it works, but it's not too clean. the goal is to have as much automated as possible. *i do not want to have to go in and change the column references every time I add a new data arra*y"
Thanks
You can use INDEX, e.g. if you have 26 possible columns from A to Z then this formula will give you your column C range (which you can use in another formula)
=INDEX(Sheet3!$A$1:$Z$250000,0,3)
The 0 indicates that you want the whole column, the 3 indicates which column. If you want the 3 can be generated by another formula like a MATCH function
Note: be careful with AND in
=AND(Sheet3!$C$1:$C$250000=$A$4,Sheet3!$B$1:$B$250000=$B$4)
AND only returns a single result not an array, if you want an array you might need to use * like this
=(Sheet3!$C$1:$C$250000=$A$4)*(Sheet3!$B$1:$B$250000=$B$4)
You could use ADDRESS to generate the text, you then need to use INDIRECT as you are passing a string rather than a range to the fomula
=AND(INDIRECT(ADDRESS(1,3,,,"Sheet3") & ":" & ADDRESS(250000,3))=$A$4
,INDIRECT(ADDRESS(1,2,,,"Sheet3") & ":" & ADDRESS(250000,2))=$B$4)
Obviously replace the 3s and 2s in the ADDRESS formulae with your MATCH function you used to get the column number. The above assumes the column for $B$1:$B$25000 is also found using `MATCH', otherwise it is just:
=AND(INDIRECT(ADDRESS(1,3,,,"Sheet3") & ":" & ADDRESS(250000,3))=$A$4
,Sheet3!$B$1:$B$25000=$B$4)
Note a couple of things:
You only need to use "Sheet3" on the first part of the INDRECT
Conditions 3 and 4 in the ADDRESS formula are left as default, this
means they return absolute ($C$1) reference and are A1 style as
opposed to R1C1
EDIT
Given the additional info maybe using an advanced filter would get you near to what you want. Good tutorial here. Set it up according to the tutorial to familiarise yourself with it and then you can use some basic code to set it up automatically when you drop in a new dataset:
Paste in the dataset and then use VBA to get the range the dataset uses then apply the filter with something like:
Range("A6:F480").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets("Sheet1").Range("A1:B3"), Unique:=False
You can also copy the results into a new table, though this has to be in the same sheet as the original data. My suggestion would be paste you data into hidden columns to the left and put space for your criteria in rows 1:5 of the visible columns and then have a button that gets the used range for your data, applies the filter and copies the data below the criteria:
Range("A6:F480").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets _
Range("H1:M3"), CopyToRange:=Range("H6"), Unique:=False
Button would need to clear the destination cells first etc, make sure you have enough hidden columns etc but it's all possible. Hope this helps.