Using String Manipulation To Create And Change Wroksheet Name.
Dec 5, 2008
i have a worksheet called 'week 1' and want to write vba code so that a new sheet called 'week 2' can be created. However i want to write code so that it doesn't matter what sheet i am on, a new sheet would be created with the name week and the next number up. ie. the last worksheet is 'week 7' then the code should be able to create a new worksheet called 'week 8' ect. I currently have this code but it keeps returning an error message. anyone know how i could do this???
Sub nSheet()
Dim nm, i As Long
nm = Worksheets(Worksheets.Count).name
i = 1
Sheets.Add
Do While WorksheetExists(Left(nm, Len(nm) - 1) & i)
i = i + 1
Loop
ActiveSheet.name = Left(nm, Len(nm) - 1) & i
End Sub
I need to be able to take someones name which is in a single cell in the format "First Middle Last" (could be more than one middle name) and then split it up so that it fits the following format:
Last name (must be 50 characters) Middle name (must be 15 characters) First Name (must be 15 characters)
I'm unsure on the right combination of operators to use to variably concatenate strings in this way. I'm confident I can figure out how to add the white spaces after a name to make it fit the character requirement but I don't know how to split the initial name up into it's 3 parts. Names longer than the character requirement will just be truncated.
I have a macro that loops through a column of text and removes all text after a hyphen. Example: AU9929-PK becomes AU9929. I need to set up some exceptions that when it processes certain text it does not truncate it. Example: AU9929-ASST stays as AU9929-ASST. So far there are twelve exceptions but this could increase.
Note: The list which includes shop number, description, sku, sku description, quantity, unit price and more is sorted in a particular order as other operations are performed on it that requires it be in a specific order.
I am trying to let the user call my subroutine in the following 5 ways but am lost using string manipulation -
Call FindReplaceAll(C, 123, 1.23) In Col C replace 123 with 1.23 Call FindReplaceAll(2, 123, 1.23) In Row 2 replace 123 with 1.23
Call FindReplaceAll(C:E, 123, 1.23) In Col C-E replace 123 with 1.23 Call FindReplaceAll(2:4, 123, 1.23) In Rows 2-4 replace 123 with 1.23
Call FindReplaceAll(C9:E19, 123, 1.23) In region C9-E9 replace 123 with 1.23
Here is what I am trying to do in psudo Sub FindReplaceAll(sType As String, sFind As String, sReplace As String) If sType does not have a colon in it then If sType = A-IV or sType = a-iv only then Columns(sType &:& sType).Select If sType = 1-65000 then Rows(sType &:& sType).Select Else
I have a sizable spreadsheet, which has one column where the cells are mostly numeric strings of up to 6 numbers - there are variations, which I will mention.
What I need to do, is to treat the numbers as individual figures, and add them, then divide by the number of figures. e.g. cell value '123456' I need to process as (1+2+3+4+5+6)/6.
The variations are that '0' has to be added as 10, and any letters need to be added as 12. '-' and '/' which are the only non-alphanumeric values should be ignored.
In sheet1 I have a simple database consisting of 5 columns of data
Column A : Name ie James Jones Column B : payroll number ie 123456 Column C : shift times ie 1245-2124 Column D : job title ie floor Column E : comments ie A/L or 0600-1500
what I would like is some code that will go down Column E and if a 'time string' ie 1300-2130 is found then copy this string and paste into corresponding value in column C. If a text string is found ie A/L or Sick or anything like this then ignore and move onto next cell, loop this until all cells in column E have been checked.
I have two questions. Below is a code snippet that demonstrates what I'm trying to achieve.
Const D_WIL_SearchString As String = "[HTML ON]*<a title=""*"" target=""blank""href=""*"">*</a>*[HTML OFF]"
If D_Info(i).WIL Like D_WIL_SearchString ThenDo AElseDo BEnd If
The double quotes ("") are supposed to represent a single double quote within C_WIL_SearchString. The asterisks are supposed to represent any characters of any length. All other characters (except for the initial double quotes (")) should be present within the string D_Info(i).WIL
I'm having issues ensuring that this code works correctly though, as it does not appear to search for the string that I'd like it to.
As a second question, I would like to know if there is a way of ensuring the asterisks (or another similar character) only allow whitespace? (i.e. spaces and new lines)
I am looping through and copying screens of mainframe data and appending them to the clipboard. Once done, I start a Notepad and paste it for future massaging. Now I need to perform a check on each screen which requires copying something from the screen, assigning to a variable, and checking it. This overwrites what I've already stored on the clipboard. Is there a way to store what I've got on the clipboard, then use the clipboard for something else, and then reload the clipboard?
The data is arranged as such, there are a list of call types and in another column, there are a list of call lengths. Currently I have a COUNTIF which searches the call type column for certain call types ie BA is off peak but this only tells me how many off peak calls they have made, I need to make it tell me how many minutes of off peak calls there are. IE this is an example Call Types Call Lengths (minutes) BA 1 BA 1 BA 3 BA 2 at the moment my formula would only count this as 4 but I need it to calculate it as 7. This is a very big data set containing around 900 entries per sheet.
Below I have a table with dates. The actual dates will be added in over time. I want to display the amount of days in the column btwn planned and actual but since it is subtracting a date from a blank cell, the #VALUE function is displayed. What function can I use to tell excel to keep the cell blank until a value other than #VALUE appears.
With my limited knowledge I am having trouble constructing formula to break the following info that I receive frequently from my credit card company into 3 columns - Date, Details, Value
I have test.txt file. The data in test.txt file so messy (there are headers and some data lines start with letter "A" and need to ignore). There's no <TAB> in data file, all are single space and <enter>. I can do nothing about data files.
Task: Open test.txt file SUM all product quantity, put result in xls file in A1 SUM all Total price in the txt file, put in xls file (same file) in B1 Close test.txt file
I need the code to create a find box into which a search string is input. The code should find the string at a particular cell, then copies this cell and four cells to the right to a location in sheet 2 of the same workbook
The code runs but comes back with a runtime 424 error. I believe the issue is being caused by "nextCell" but I cant see why.
Sub FindStrings() Dim firstCell, nextCell, stringToFind As String ' Show an input box and return the entry to a variable. stringToFind = _ Application.InputBox("Enter J Number and Stage Number. For Example J1234 ST1", "Search String") ' Set an object variable to evaluate the Find command.
This forumla generates a number for each player, the higher the number the more inline they are to get a game
Problems are this works for the 29 weeks of this year but more weeks need added to the end of the year as we get there. Can i generate the array numbers from a formula and shorten.
This is a sample data ignore row 2( just a count of players) and data actually goes back to 6th Jan
Is it possible to create a string with a range of numbers
1 3 4 5 6 8 10
Result: 1,3:6,8,10
Or
1 2 3 4
Result: 1:4
Or
1 3 5 7
Result: 1,3,5,7
Where consecutive numbers are separated by a ":" and other numbers by a ",". I use the following function to create the ","-concatenate, but I don't know how to create the ":"-ranges.
Function AConcat(a As Variant, Optional Sep As String = "") As String 'By Harlan Grove, March 2002 Dim Y As Variant If TypeOf a Is Range Then For Each Y In a.Cells
Where all question 1 fields are put into a row, 2 in another row, etc (this may be more than 2 sets of questions), grouped by the name field. I have had a look at Pivot tables but they dont seem to do what Im after.
My pivot table is not auto summing each column properly, and I can't manually enter a formula to do so. I tried adjusting the settings of the rows and columns through the pivot table wizard, but no luck. Is there a way around this limitation?
i have a string in a cell, that would say "Your results are -10% for the week". is there any way to change the font to red, for the number, including the minus sign preceeding it, and the percent sign following it. all are in one column, about a thousand rows. the rest can stay black.
I am looking for a while for a macro or a function, which should change needed letters in string into needed ones.
Example: A1 cell contains words "John Johnson Martinson". I want to switch "n" letter into my specified, lets say "m" and the result should be "Johm Johmson Martimsom".
I would like to get it within range of columnA. Is it possible to get?
I have a program that updates values quarterly when run. The spreadsheet that it works with also contains a couple of pie charts that correspond to the updated data. the charts only have one series with category values. I recorded a macro to see the code excel uses for creating a new chart and tried to modify the statements to my needs but have been running into runtime error 1004 ("Method ' Cells' of Object '_Global' failed"). The code is as follows I don't have any trouble until the last two statements.
Sub Chart_Updater() Sheets(Chart1var).Select With ActiveChart .HasTitle = True If Chart1var = "COLI VUL 1 Fund Chart" Then .ChartTitle.Text = "COLI VUL 1 Allocation by Fund Provider " _ & sday & "-" & sday & "-" & Lyear ElseIf Chart1var = "COLI VUL 2 Fund Chart" Then .ChartTitle.Text = "COLI VUL 2 Allocation by Fund Provider " _ & sday & "-" & sday & "-" & Lyear ElseIf Chart1var = "COLI VUL 7 Fund Chart" Then .ChartTitle.Text = "COLI VUL 7 Allocation by Fund Provider " _
The variables fundtr1, fundtr2, and emptycolvar are public, and are all returning values, so there is no problem there. Also I can't use ranges like "A1:F7" because the range needs to be variable.
This is column a and b. Looking at b I am looking for a formula that will pull the first capital letter out of each word like ACR to create color codes.
how to make upper case after mark "." (dot), see this below :
sample data after formula Tabrani,Ny.yusmaniar Tabrani,Ny.Yusmaniar Badu Zai,Tn.surjaah R & Darussamin Badu Zai,Tn.Surjaah R & Darussamin Zainal Arifin,Ny.elvyati Zainal Arifin,Ny.Elvyati etc..
it's possible with excel code? if could perhaps not macro.
I've created a humongous spreadsheet in Excel- 26 million cells and a file size of about 500mb. The result of these calculations is a pattern derived by conditional formatting. I'd like to get the pattern into Photoshop- It would actually simplify image manipulation in Photoshop to lose the cell data, and the underlying formulas are of no use.
The file seems to be too big to save into a PDF file. Is there another way to get the Image into Photoshop?. The other alternative is to reduce the file size by stripping out unnecessary cell data and formulas without losing the pattern.
I am trying to create a combobox to filter a set of data by the month that is entered.
The below code worked fine when there was just the month entered, but now all the entries in the sheet are in the format 01 January 2009. So I need a section of code which will search for the combobox value as part of a string in my range.