I want to keep second word of all the cells in a column. Is this possible? I want to do this without using reference.
Column1
hi hello
you me
zero ten
stack overflow
Notice it is just one column. I want to tun this column into:
Column1
hello
me
ten
overflow
Is this something possible? I know how to do it using additional column as reference but not sure how to this job all in one column. I'd appreciate for help.
Without using an extra column, you could do it with VBA. Select the cells you wish to process and run this small macro:
Sub SecondWord()
For Each r In Selection
v = r.Value
If InStr(v, " ") > 0 Then
r.Value = Split(r.Value, " ")(1)
End If
Next r
End Sub
Macros are very easy to install and use:
ALT-F11 brings up the VBE window
ALT-I
ALT-M opens a fresh module
paste the stuff in and close the VBE window
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE window as above
clear the code out
close the VBE window
To use the macro from Excel:
ALT-F8
Select the macro
Touch RUN
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
Macros must be enabled for this to work!
Related
Excel I need it to delete what I type right after I press enter is this possible? This might be easy but I don't know how to.
Yes I am using this data I need it to send the data and then delete itself with the results from that data in.
This is what I have so far: "=COUNTIF(B2;C8)" so if the b2 matches c8 then it adds one and I need it to delete the b2 automatically so that I could enter new value.
Go to File > Options. This will open a window, select the second tab Formulas. Check the box Enable Iterative Calculation.
Note, that this box will uncheck itself if you install updates.
Ta da!!!
Place the following event macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Target.ClearContents
Application.EnableEvents = True
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!
As an office policy, I am required to ensure that there are no errors (i.e. #div,#ref) in any of the excel files. We have a software which lists down all the excel errors.
In few excel files, there are 50 tabs,and each tab has multiple errors.
To remove all excel errors. I press ctrl+c, the ctrl+g (go to) ,the click on special,then check errors in formula. This selects all excel errors only in that sheet and I press delete.Hence all errors are deleted in that tab
Is there anyway,in which all excel errors in all tabs can be removed at one go?
Consider this small VBA macro:
Sub Macro1()
On Error Resume Next
For Each sh In Worksheets
sh.Select
Cells.SpecialCells(xlCellTypeFormulas, 16).Clear
Next sh
End Sub
Macros are very easy to install and use:
ALT-F11 brings up the VBE window
ALT-I
ALT-M opens a fresh module
paste the stuff in and close the VBE window
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE window as above
clear the code out
close the VBE window
To use the macro from Excel:
ALT-F8
Select the macro
Touch RUN
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
Macros must be enabled for this to work!
EDIT#1:
this version will work on hidden sheets:
Sub Macro1()
On Error Resume Next
For Each sh In Worksheets
sh.Cells.SpecialCells(xlCellTypeFormulas, 16).Clear
Next sh
End Sub
It is possible, but please don't do it. Try fixing your formulas so they don't display errors. For example, If you are getting a Div/0 error then check to see if the denominator is 0 before dividing.
Deleting the errors will make the file a nightmare to troubleshoot or work with in the future.
Im trying to get a msgbox when the value in the cell which is updated with a formula is less than zero.
For example:
a1= 5
b5= a1
if b5 is less than zero then msgbox "your value is less than zero"
Hope someone can help me
Thank you!
Include the following event macro in the worksheet code area:
Private Sub Worksheet_Calculate()
If [B5] < 0 Then
MsgBox "your value is less than zero"
End If
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!
I want to combine text of 1000 cells of a particular column (say from A1 to A1000) to one single cell (say A1001), can anybody tell the macro for this?
Try the following UDF
Public Function concat(r As Range) As String
concat = ""
For Each rr In r
concat = concat & rr.Value
Next rr
End Function
User Defined Functions (UDFs) are very easy to install and use:
ALT-F11 brings up the VBE window
ALT-I
ALT-M opens a fresh module
paste the stuff in and close the VBE window
If you save the workbook, the UDF will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the UDF:
bring up the VBE window as above
clear the code out
close the VBE window
To use the UDF from Excel:
=concat(A1:A1000)
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
for specifics on UDFs
Macros must be enabled for this to work!
=concatenate(A1:A1000)
As the formula in A1001
Sub MergeRanges()
Dim rng As Range, txt As String
For Each rng In Selection
txt = txt & rng.Value2
Next
Application.DisplayAlerts = False
Selection.Merge
Selection = txt
Application.DisplayAlerts = True
End Sub
when merge cells, i want to remain all the data in the cells. i googled some time,finding the above code. but i don't know how to use it? and what's the meaning of them. thank you.
Setup:
Open VBA editor (Tools > Macro > Visual Basic Editor) (shortcut Alt-F11)
Insert > Module
Paste the code into your new module.
Use:
Select the cells you want to merge.
Tools > Macro > Macros... (shortcut Alt-F8) > select MergeRanges > Run
If you want the macro to work with "special formats" such as dates, then you should change .Value2 to .Text.
in Excel, press Alt-F8
use the dialog to add an empty macro "MergeRanges"
add your code above.
To run the code, select some cells you want to merge, press Alt-F8 again and run that macro.
Highlight some cells you want to merge (not dates or currency) and the press Alt+F8 an select this macro. It should (I didn't test) merge the cell contents into a cell without losing any of the contents that were in each cell.
Make sure to insert that code in the file first by pressing Alt+F11 to open VBE and right click the explorer and choose add module. Then paste this code in. Make sure your macro security is low enough to run it.