Custom Code To Output Cell Range As String
Nov 19, 2013
I have come across this wonderful piece of code that kind of accomplishes what I am after, to a point. Though I would like the output string to be displayed with a few extra characters.
Code:
Function Concat(rng As Range, Optional sep As String = " , ") As String
Dim rngCell As Range
Dim strResult As String
For Each rngCell In rng
If rngCell.Value "" Then
strResult = strResult & sep & rngCell.Value
End If
[code].....
I want the output to be:
["cell1" , "cell2" , "cell3" , "cell4" , "cell5"]
View 2 Replies
ADVERTISEMENT
Jun 13, 2013
How to modify a custom cell format to make data entry easier.
My goal is to have the output look like this: 'A12B-C20D: SET 10: Text string here'
Inputs needed are:
1-3 digit number between A & B
1-3 digit number between C & D
1-2 digit number after SET
Text string of variable length
Where I am stuck. So far I can get "A12B-C20D: SET 10:" to show up properly when 122010 is input. The custom format I am using looks like this: "A"##"B-C"##"D: SET "##": "
When I try to incorporate the "@" symbol the first part of the formatting goes away and the output shows up as "122010 Text string here".
I have tried:
"A"###"B-C"###"D: SET "##":";;-;_@
"A"###"B-C"###"D: SET "##": ";;@
"A"###"B-C"###"D: SET "##":";_@
"A"###"B-C"###"D: SET "##": ";;;@
View 4 Replies
View Related
Mar 25, 2014
As per title, I am trying to compare a column of text cells which contain "Yes" or are empty and a columns of numbers. If they are "Yes" and "1" on the same row, I want to output an "OK" message. Excel seems happy with the following code but it does not work and returns an empty cell if the two conditions are true.
[Code] .....
View 6 Replies
View Related
May 2, 2014
I have an Excel 2010 spreadsheet that I am using to save several numbers all in the same column. These numbers can range from the several thousands up to billions. The formatting I am using for these numbers is Number (using 1000s separator).
number_forma.png
I am also using the spreadsheet to generate a text string for each of the numbers. I don't want the text string to show the number as it is, I want to shorten the number by only showing the first few digits followed by a "B" for billion, "M" for million, or "K" for thousand. For example, in the text string I want to show 1,600,000 as 1.6B.
In order to shorten the number I use the cell in the column to the right of each number. This cell uses the following custom formatting (which I found by doing a Google search): [>999999999.999]#.0,,,"B";[>999999.999]#,,"M";#,"K";
custom_format.png
As you can see the formatting is quite complex (at least for me it is) but it does what I want it to do.
Here is a screenshot of what the original and custom formatted cells look like:
custom_formatted_cells.png
As you can see the custom formatting works and does exactly what I wan
The next column (after the custom formatted number) is where I put the generated text string for each of the numbers. As I stated above, I want the generated text to use the shortened version of the number (e.g. 1.6B).
To generate the text I use the CONCATENATE function with a reference to the cell containing the shortened number as one of the arguments. For example:
CONCATENATE("SOME STRING ", B1)
Where B1 is the custom formatted cell.
The problem I am running into is, the text that gets generated doesn't show the shortened format of the number, it shows the full number. Here is a screenshot demonstrating what is happening:
concatenate_formula.png
As you can see the generated text is "SOME STRING 1600000000". This is not what I want. I want the generated text to be "SOME STRING 1.6B".
I think I understand what's going on. When the CONCATENATE function references a cell it takes the actual value of the cell and ignores any formatting. (I suppose formatting is just the way you see the data, not how underlying functions receive the data.)
My question is, how can I re-write the CONCATENATE function (or use another function, etc. available to me) to use the formatted version of the cell?
*UPDATE* I have attached my spreadsheet as an attachment to this post (tackyjan_excelforums.xlsx). Please note that it was created and saved using Excel 2010.
View 8 Replies
View Related
Mar 31, 2014
I am trying to do a sort of index match thing using VBA. What I am attempting to do is to use the prefix of a long number and try to find that exact prefix in a string array, and output that string array value. So this is what I have so far as a test:
[Code].....
So I can match the text exactly so if I put PREFIXB in cell A1 in this example, i will get the msg box saying "YES", but if I make it PREFIXB1231k4j3jj1kj32cj, it will display "NO". I want to get it so that PREFIXB will be displayed in the cell that I put the formula in. So if A1 = "PREFIX1AAA100CF" and cell B1 = "=ABC(A1)", cell B1 will display "PREFIX1AAA".
Now the thing is that these prefixes can have different lengths, but will never encompass the exact prefix of another. So if I had a prefix of: PRE1AB, I won't have a prefix of PRE1A.
View 2 Replies
View Related
Jul 26, 2006
How does one pick up the data contained in a worksheet cell (say B5) and use it in the vba code of a custom function without passing the cell as an arguement
View 3 Replies
View Related
Apr 22, 2013
=AVERAGEIFS(MFI,DATE,">="&JanStart,DATE,"<="&JanEnd)
MFI is the named ranged that is referencing a column of data. This works, but I want to be able to change the MFI to a different named ranged.
So what I am trying to do is using an ActiveX Combo box so I can reference the named ranges that I have set, for example MFI, so each time a user chooses MFI or another named range, it will output to a linked cell (A1). Then the linked cell will be referenced into this forumla.
=AVERAGEIFS(A1,DATE,">="&JanStart,DATE,"<="&JanEnd)
Is it possible for A1 to be linked to the named range, so if the user choses MFI in the combo box, it will change all AverageIFS formulas to look at a different named range.
View 3 Replies
View Related
Oct 9, 2006
I have a spreadsheet with Approx 900 rows of information that has been entered incorrectly.
Spreadsheet has 6 columns.
Contact Name
Contact Number
Company Name
Company Account Number
Order Date
Order Numbers
Every Order should have its own line - However I have approx 900 rows where the order numbers have multiple entries instead of single entries.
All the order numbers end "LO" and there all 8 digits long.
I wanted to know if its possible to use excel to look for all instances of "LO" in the column Order Numbers and delete the original Row and replace it with 3 rows with the same information.
Example:
Attached to this post!
I have 15 historic files each approx 35000 rows and I suspect there are more errors
View 9 Replies
View Related
Jul 3, 2009
I am performing a lookup using the populare user defined function nlookup, which does not take a lookuparray argument to find lookup values. But I only want to return lookup values that fall into a certain array. To accomplish this, I figured out that I need a way to specify a condition of the type "if cell address of lookup value falls within range"
It should be possible if I find a way to return the cell address of the nlookup value, but as nlookup is not limited by a lookuparray argument, so I was not able to use the address/index/match that come up in similar questions.
View 3 Replies
View Related
Jul 23, 2014
I have months ( 1 to 12 ). Every month, a set of tasks need to be executed which takes "x" number of hours.
So if I have 1 machine working 3 hour in the month 1, the total time spent is 3 hours. Fairly simple right !
Say on month 2, a set of tasks take 4 hours. total time that my first machine takes is 4 hours. But i want to introduce 3 new machines in this month, which will execute the first month's tasks. So total time spent here is ( 3*3 + 4*1) = 13 On month 3, task time is 6 hours. And I am introducing 2 new machines.
So total time is 2*3 ( time taken for 2 new machines to perform first month's tasks ) + 3 * 4 ( 3 new machines introduced last month will now execute second months task) + 6 * 1 ( time the first machine will spend on month 3 s tasks ) = 24
View 2 Replies
View Related
Feb 17, 2014
I am trying to create report of the in and outs of tools we are shipping for repair.
Currently in Tab 1
Column F - Date shipped for repair
Column G- Vendor Name
Column H- Date Returned
What I need in Tab B
Vandor - Total Sent- In Repair @ Vendor- Total Repaired - Total Unrepaired
Here are Images if it makes it a little easier to understand
The Info I currently have
image1.png
The info I required filled out based on the previous data
image2.png
View 6 Replies
View Related
Jun 4, 2014
Attached is my sample data Sample Data_Combine Sheets.xlsm.
What the code in the attached sheet does is that it combines the data in Sheets Set1 and Set2 into the worksheet named "Combine".
Both input sheets share same columns. Code I use is as below:
VB:
Sub BuildPivotData()
Dim wrsht As Variant
Dim i As Integer
Sheets("Combine").Range("A2:AI500").Clear
wrsht = [{"Set1", "Set2"}]
For i = 1 To UBound(wrsht)
Sheets(wrsht(i)).[a2].CurrentRegion.Offset(1).Copy Sheets("Combine").Range("A65536").End(xlUp)(2)
Next i
End Sub
I want to amend the output in such a way that when the macro is run , in the "Combine" worksheet an additional column is added at the start(col A) with header as "Category".
The category should be nothing but the input Sheet name i.e Set1 or Set2.
Here is an example ... Output Sheet.xlsx.
View 3 Replies
View Related
Sep 15, 2014
In the code below how do I get the Current ROW number the "For Each Cell in Rng" is processing
I tried "cRow = rng.row" but it's only showing the starting row not the current row of CELL
VB:
Sub Process Range()
Dim startCol As String
Dim startRow As Long
Dim lastRow As Long
Dim lastCol As Long
Dim myCol As String
[Code]...
View 2 Replies
View Related
Sep 10, 2008
If I have a cell (a1) containing the text "Sage, Navision, Hardware" how do I write a sumif formula that will add up a set of numbers based on cell A1 containing the text string "Navision" (for example)
View 9 Replies
View Related
May 24, 2007
I don't understand what I am missing. but I can't paste a string into a cell [range.cells(x,y).text = string]
Here is my ' ' -delete any rows that contain "Fab 11"
' -rename any cell that has "Supply x" (Delete " supply x" from text)
Dim cellText As String
Dim i As Integer
Dim lastRow As Long
Dim rngSigac As Range
Dim wb As Workbook
Dim ws As Worksheet
View 9 Replies
View Related
Feb 11, 2010
I want to set my output range to start at row 25 Set Findit starts counting cells from row1.
View 2 Replies
View Related
Oct 9, 2007
I'm trying to output a couple columns (and 300 rows) to a csv file. This code works wonderfully, save for the fact that it doesn't igore any cells in the range that are empty.
how I can get it to ignore empty cells?
Public Sub textFileDelim()
Const DELIMITER = ","
Const MYFILE = "E:EricTesting Folder2_Thurs.csv"
Dim Last_Column As Integer
Dim Last_Row As Long
Dim Row_Loop As Long
Dim Column_Loop As Integer
Dim FileNum As Integer
FileNum = FreeFile
View 4 Replies
View Related
Feb 15, 2010
I've posted this query before, not on this forum, but I don't think the replies I've had so far are going to do what I want. Initially I was looking for a formula, but the suggested pile of nested IFs won't work for the number of conditions. I saw a previous post on here for a VBA macro to search for a text value in a cell against the cell contents of a range and it seemed to do at least the first part of what I wanted. I attempted to manipulate it a little to test its applicability for my own nefarious purposes but for the life of me I can't get it working.
This is complicated by the fact that the actual data is commercially confidential, so I can't show you the actual file, but I can fake what I want with two simpler ones. I've attached them to this post. What I want is a fair bit more complex than the other post I found - I want to be able to compare a partial text string from a given cell in a range ('Check Value' in the attached TestBook2 ) against the strings in a range of cells ('Value 1' in TestBook1), and return the corresponding value from 'Test Value' to the corresponding adjacent cell to the tested 'Check Value', with an order of precedence, for example...
Testbook2 contains an entry in C5 of 'a, e, h, z, x, y'. Testbook1 shows that the return for a, b, c, or d is 'moo', for e, f, or g is 'steve' and for g through q is 'fred', all others being no returned value. Moo>steve>fred, so I want the corresponding 'moo, steve. fred or <blank>' cell to contain 'moo'. Conversely, C6 contains 't, u, z' and therefore shouldn't have a value in 'moo, steve, fred or <blank>'. C12 contains 'f, z, s, y, u' and C15 'i, x, z, s', and therefore should display 'steve' and 'fred' respectively.
View 3 Replies
View Related
Oct 9, 2007
I would like to output the text I perpared in " sheet 1" into a text file, "output.txt"
The imformation I like to output start from coulmn C, and column D then column E.....
The numbers of rows in each column could be different, and also there may be some single empty column in between. The totals numbers of coulmn is unknow.
the text in the output.txt should contant all the imformation in the sheet started from column C, coulmn D, column F.... (if coulmn E is empty). and the text in the output.txt file is continues with no gap in it.
To make it even more powerful for later use, The column that begin with NOT should not be output.
Example:
Excel Data-
A____B____C____D____E____F____G____H____I____J
1a....1b.....1c.....1d............Not.....1g
................2c.....2d............2f......2g
........................3d............3f......3g
........................4d
output.txt-
1c
2c
1d
2d
3d
4d
1g
2g
3g
View 4 Replies
View Related
Mar 12, 2009
I have a Macro that I have recorded that autosorts several columns for me. This works fine as I have 5 columns that need to be sorted in a particular way.
The problem is that I have a custom list which I stored using the: Tools>Options>Custom List tab. Now this works fine on my pc as I have the custom list stored on my PC.however the problem is when someone else uses it on their PC it may no longer work as they won't have my custom list stored on their PCs.
Is there a way to store the custom list in a Macro and then use that list to sort to the criteria needed. For example "One, Two, Three, Four" will not store in alphabetically, so hope would I be able to sort so that they would appear in a chronological manner? Below is the code for the Macro I recorded. As you can see one of the lines says "OrderCustom:=6"; this I am assuming is reading from the list I created.
View 2 Replies
View Related
Dec 5, 2013
I am looking for a formula that will output the highest and lowest value in a range. Column A contains a range of numbers, some of which repeat and in column B i'd like to extract ONE instance of the highest and lowest value in Column A, preferable the last instance.
See example below and in column B the desired output.
Column A
160
90
120
90
120
160
Column B
blank
blank
blank
90
blank
160
View 5 Replies
View Related
May 10, 2006
I want to pass an array to a function, and am unclear how to do it. For example, the following declaration does not work:
Public Function xyz(a() as Variant) as Double
There is an additional requirement that I would like the output also to be a range of the same dimensions, typically one column and 100 rows. Is this possible?
A further twist is that the function I am writing calculates two values for every element in the input array and I need the output of them both.
An inelegant solution would be to write two separate functions, but I was wondering if it is possible to get two array outputs from a single function.
View 7 Replies
View Related
Dec 2, 2008
A spreadsheet that needs a new menu item in a custom menu does not show the custom menu code. Tools-->Customize-->Commands-->Rearrange Commands shows the menu and allows me to add a new menu item and macro.
After saving and exiting excel and going back into the spreadsheet, the new menu item is gone. How can I find the code to do this to keep the menu item? In the VBE, I looked in the object browser(F2) in all of the libraries and could not find the code. In the workbook_open and workbook_activate I can disable it with CommandBars("Worksheet Menu Bar").Controls("menu").Delete and it disappears.
View 14 Replies
View Related
Dec 21, 2006
I have added a toolbar to an excel application that the company uses. I need this toolbar only to be accessed to this application and not any time that you open excel. I have used the following
Private Sub Workbook_Open()
Application.CommandBars("Rithin-Toolbar2006").Enabled = True
Application.CommandBars("Rithin-Toolbar2006").Visible = True
go_cover
End Sub
Private Sub Workbook_close()
Application.CommandBars("Rithin-Toolbar2006").Delete
Application.CommandBars("Rithin-Toolbar2006").Enabled = False
Application.CommandBars("Rithin-Toolbar2006").Visible = False
End Sub
This works but only If I accept yes when it prompts me to save changes to the workbook. Each time I open the workbook and close it, it prompts me to save changes to the workbook. I dont want to force a save on the workbook, meaning have code that will save the workbook before closing. I want it such that if the user opens the workbook, and makes no changes, he/she should just close it with no questions asked.
View 6 Replies
View Related
May 21, 2007
Has anyone got the add in code? I have my own custom menu bar on my excel. But every time i want to add a new link i must go into the code and manually add the file name extension and relevant VBA code. Is there a method of just entering the file extension in a cell range and excel will automatically update or pick up or link from this location?
View 9 Replies
View Related
Mar 21, 2008
I am trying to use the worksheets.add method with the Type specifier pointing to a file location containing a worksheet template.
View 9 Replies
View Related
Feb 14, 2014
Trying to look for formula for searching through Range and search through Data to achieve expected res
Data Output ExpectedRange
Pune 123 is city Pune 123 Mumbai 999
Maharashtra 345 is state Maharashtra 345Pune 123
India 678 is Country India 678 Nagpur 666
Maharashtra 666 is state OthersPune 555
Below is the query i used for manual search however need formula to see through Range and achieve output expected
=IF(ISNUMBER(SEARCH("Pune 123",A5)),C5,
IF(ISNUMBER(SEARCH("Maharashtra 345",A6)),C6,
IF(ISNUMBER(SEARCH("India 678",A7)),C7,"Others")))
View 5 Replies
View Related
May 21, 2014
I need a 'simple' vba that outputs all the dates in a range that correspond to a particular ID in a column as well as that same ID in a column beside the dates.
So basically using the data in columns A to B as input, to get columns E and F as output.
Also, for a lot more than just 3 IDs.
View 3 Replies
View Related
Nov 19, 2012
I am experiencing odd behavior with Excel (v. 14). When a spreadsheet is opened, format setting of almost all cells in the workbook have changed to a custom code that reads "[$-409]0%". AFAIK the first part is not even a valid tag.
Because the underlying data is not changed, I can just select cells and reset formatting to "Number" or "General" and everything's fine. However, I'd like to get to to the root of the problem.
The problem occurs with only some workbooks. I should mention that the workbooks are circulated in different language versions of Excel, which may contribute to the problem.
View 2 Replies
View Related
Feb 22, 2007
Option Explicit
Dim cMenu1 As CommandBarControl
Dim cbMainMenuBar As CommandBar
Dim iHelpMenu As Integer
Dim cbcCustomMenu As CommandBarControl
'(2)
Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")
'(4)
Set cbcCustomMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup)
'(5) Give the control a caption................
I have created several spreadsheet with customized menus. In step 5 when I type
a period the options for selecting Caption does not appear. In step 6 the 'Control' word didn't appear in list. Sometimes the options in step 6 do appear BUT not the option for Controls. I have created spreadsheets with menus that work but the only way I could do it was to cut and paste from the website and then modify it.
View 3 Replies
View Related