Create Excel VBA to delete specific text from cell in one column - excel

I am trying to create an Excel VBA that would delete only a specific part of the cell in only one column.
In Column A, I have a directory values:
For example:
Directoryof K:\data\Admin\
What I would like to do is remove the "Directoryof" from all the cells in column A and leave only the remaining text that follows it.

To create a macro to perform the above follow the below steps:
Click the "Developer" tab on the top menu.
You will find an option "Record Macro".
Click the Record Macro ->
a. A dialog box appears, give your macro a name
b. Shortcut key (if you want) can give by pressing (shift and any key such as
letters)
c. Store macro in : This workbook (this allows your macro to run on this sheet).
Click on "Use Relative References".
Once you are done, just perform the delete operation ( by removing the portion you do not want) on one of the column so that the macro may record the process which you are performing.
Once done, below at the lowest pane you will find Stop Macro option (a small blue square box). Click it to stop the recording of the macro.
Now you are ready with a macro to replicate the same without you performing the operation.
Just goto any other column where you want to perform the operation and click on "Macro" option on the developer tab and then click on your created marco, and you will see the magic happen.

You could probably use regex to accomplish what you are going for. Regular Expressions are often used for finding patterns. If all of your follows the same format, you could break your strings apart into two capture groups with something like:
(.+)([A-Z]:\\.+)
https://regex101.com/r/uD4uJ0/2 <-- this will show you your capture groups
Edit: I updated this link, sorry, originally had the wrong one.
This here How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops will show you how to split up capture groups if you are interested.

You could use something like text to columns, fixed width, and split the columns after Directoryof and then copy/paste the values back into column A.
I'm not sure if there's a method to do this without a helper column without VBA. If you can afford to use a second column, you can also use =LEFT(Cell, # of characters) assuming that the part you want to strip off is always "Directoryof" and then copy/paste values back into column A.

Related

Insert Table header Row when column value changes

I have a table of overdue customer invoices. Each customer could have several overdue invoices and I want to collate these into separate customer tables, with a sum total of due amount.
I want this to be in one worksheet, with the header row above each customer table.
Therefore, I'm looking for a VBA macro that will go through the data in column A and when it sees a change, from one customer number to the next, it totals up the values for that customer and inserts the header row, ready for the next customer. And continues on...
Example sheet Here
Sheet(tab)1 shows raw data, sheet2 shows how the formatted data should look.
I'm stumped sorry and any help or direction appreciated. Hope the info is clear.
To get started I suggest you search google "creating vba macros read and write column"
Are you familiar with VBA macro? If not, you could use a combination of index, and match formula.
Otherwise VBA solution logic, in VBA editor - which is accessible by Alt +F11:
Click on the sheet you want your VBA code to apply to and start writing your function. For example a function to check a cell range called "myFunction" would be as follows,
A single example:
Sub myFunction ()
If range.("A1").value = "Customer1" then
Range("B1:E1").Insert([Shift], [CopyOrigin])
end If
Sub End
More work required to check condition on event, dynamic insert, and will need to be wrapped in a loop. The below are tutorials specific to the job you need to program your macro for.
VBA copy and paste code if condition is met tutorial here : https://youtu.be/qGZQIl9JJk4
VBA insert tutorial here : https://powerspreadsheets.com/excel-vba-insert-row/#Excel-VBA-Constructs-to-Insert-Rows
VBA How to SUM Totals At Bottom of a Column Dynamically : https://youtu.be/_0Vcnb3xdOM
The first question is-- What VBA have you tried?
Next, change col A heading to Customer, and col E heading to Amount
because these are the desired output headings .
Next, did you know that by dropping down View, and then Macros,
that there is a RECORD button? Click it.
Finally, it records your pressing Insert / PivotTable on a New sheet.
Drag the Amount field down to the Values box
After you drag each of the other fields to the Rows box,
left click on it in the Rows box, and select FieldSettings --
Subtotals tab -- Automatic for Customer, None for the others
Layout tab -- Show item labels in tabular form for each field
and just for Customer field--Insert page break after each item
At the end, click on any cell of the pivot, select PivotTableOptions --
Totals&Filters tab -- unclick Column totals
Click PageLayout,
then Margins -- make them narrow
then Sheet -- Rows to print at the top
Maybe Header -- Custom Header
Finally click on View / Macro
StopRecording
Presto, now the VBA has been captured.
Ok, so all you have to do is insert a Subtotal. Check out these screen shots.
Before:
After:
Depending on which version of Excel you are using, would probably determine how to navigate to the Subtotal button. Google for that, if you can't fine it. Should be super-simple.

Excel formatting time as regular numbers

I've pasted into an excel file lots of number such as 43:11 or 22:06. These represent goals scored and goals against. However excel is recognising them as dates and times. I want it so that I have two columns with 43 and then 11 for example, instead of 43:11. Whatever I have tried it has become confused because it things of it as a time. I've tried formatting as text, numbers etc. Any ideas?
This will work in Excel 2016 (other versions have the same functionality but the menus may be slightly different):
Copy your numbers to the clipboard
In Excel, select the Home ribbon
Click the downward arrow under the Paste button (the leftmost icon on the ribbon).
Select Use Text Import Wizard
Wizard appears. Make sure Delimited is checked and My data has headers is not checked.
Click Next.
In the Delimiters group, uncheck Space, check Other and in the box next to it type :
Click Finish
If you are typing values into a cell, then format the cell as Text before typing. If you are importing material from an external source, then tell the Import Wizard that the field containing these values is Text.

is there a shortcut to open filter>contains box in excel?

I use filters a lot.
Filter > contains option
But it is slow because everytime i need to do several clicks.
So, my question is, is there a shortcut to open filter, drop down, contains window?
Assuming you start with filtered data already, you need to have the header cell selected. From there: ALT+DOWN, F, A.
If the filter is not already created then throw in a CTRL+SHIFT+L at at the start.
If you are not in the header row, some combination of CTRL+ARROW keys can get you there. Ideally you have a block of data and can use CTRL+UP if you start in the correct column.

Is there a way to transfer MSWord numbering bullets to MSExcel column?

I have been using MSWord 2010 to compose list of questions. These questions are organized in single MSWord document, using numbering - 1. first question, etc...
I was wondering could contents of each bullet be transffered to MSExcel cell? So if i have 20 questions, i would have cell with 20 rows, each containing one question.
I am asking this because i have 300 questions that i want to import to excel.
It's possible to copy your numbered bullets from Excel to Word and then break them up using Excel worksheet functions. However, it's real easy to just do it with the built-in Excel commands.
In Word:
Increase the width on the hanging indent on your numbered list. It will make the conversion in Excel easier to deal with.
Select your bullets and copy them.
In Excel:
"Paste Special" the copied text into Excel using the Match Destination Formatting option.
Select the cells you pasted the bullets by the number of digits in the bullets (i.e., first do 1-9, then do 10-99, etc.)
With the cells selected, choose the Text to Columns command from the Data tab on the ribbon.
Make sure that the 'Fixed Width" radio box is selected on the dialogue box that comes up, then move to the next step.
Adjust the break lines so that there are three fields: one with the number + period, another the spaces between the numbers and text, the third the text.
Moving to the next step - select the second field (the spaces) and click the "Do not import column (skip) radio button.
Click finish and the bullets are imported.
The above answer is best if you have an already established list. The best workflow I've found for this is to create a table to work in, in word. That table then copies perfectly into cells in excel, allowing you to create a structure that will pass between the tow docs seamlessly.

Modify the results in "Find and Replace" dialog for Excel 2003

My end goal is for "Find and Replace" to take an extra parameter and to show me a custom column in the "Results" table when I click "Find All".
When I search a spreadsheet for "value" and click "Find All", the dialog shows me the Book, Sheet, Name, Cell, Value, Formula for every cell that has "value" in it. But I want it to show me the contents of another cell in that row as well. I would like that cell to be from a column I specify when I enter the seach parameters.
I'm relatively new to programming, and am sure that I can figure out something with Python or AutoHotKey. But I would be surprised if there isn't a better way.
I don't want something that is associated with the spreadsheet or workbook specifically, so it needs to be part of Excel or stand alone (not a macro from what I understand). Is it possible to modify the Find and Replace dialog box in Excel?
A point in the right direction would be much appreciated, thanks!
It's not possible (at least with any sensible level of effort) to modify the built-in search functionality to add parameters and to display different output. You would need to create a similar tool in your language of choice and build in your new requirements.

Resources