|
Reverse the Contents of a Cell in Excel - UDF
Reverse cell contents with this free Excel UDF (user defined function). This will mirror all cell contents regardless of the type of content contained in the cell. This includes numbers, text, or a mixture of both. The only argument for this function is the reference to the cell which you want to mirror and, as a result, this is a very easy to use UDF in Excel.
Where to install the macro: Module
UDF to Reverse the Contents of a Cell in Excel
Function REVERSE(rCell As Range)
Dim i As Integer
Dim StrNewNum As String
Dim strOld As String
strOld = Trim(rCell)
For i = 1 To Len(strOld)
StrNewNum = Mid(strOld, i, 1) & StrNewNum
Next i
REVERSE = StrNewNum
End Function
How to Install the Macro
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.
Or For other ways to get there, Click Here.
For Excel Versions Prior to Excel 2007 Go to Tools > Macros > Visual Basic Editor
For Excel 2007 Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.
- If the Macro goes in a Module, Click Here, otherwise continue to Step 8.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Go to Step 8.
- If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Go to Step 8.
- Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.
- You are now ready to run the macro.
Similar Helpful Excel Resources
Hi -
I am trying to write a formula to reverse data in a cell.
Basically I am converting a number to hex then I want to take that hex string and reverse it.
So it would be something like this my original number is 400001001 my hex number would be 17D787E9 because I am only allowing it to show 8 characters. I want to reverse the 17D787E9 to read 9E787D71.
My question is:
How can I reverse that cell?
I have searched google and this forum and can't seem to figure it out.
I am sure I could do it in VB but I don't know any VB code.
Thanks for your help!
I have a name convention in one cell that has the last name first serperated by a comma with the first name last. How can I reverse this to show the first name first and the last name last in one cell?
All of the information is provided in one cell, which I can not change. If possible I would like to pull the names from the middle only (example: cell d11 only give me Adam Diaz and so on). Once I have pulled out the name, I would to reverse the name (example: Diaz Adam). Is this possible??
d11= ADIAZ01 Adam Diaz (adam.diaz)
d12= AELIZO02 Alejos Elizondo (alejos.elizondo)
d13= BDELUN00 Bobby Deluna (bobby.deluna)
d14= BFOREM00 Bud Foreman (bud.foreman)
d15= BGREGG00 Billy Gregg (billy.gregg1)
d16= CGREEN06 Christopher Greenwood (christopher.greenwood)
d17= CGREEN08 Cheryl Green (cheryl.l.green)
d18= DDOWNS01 Dickie Downs (dickie.r.downs)
d19= DFLORE03 Daniel Flores (daniel.flores3)
d20= DMENDE01 Donald Mendez (donald.mendez)
d21= DMORAL01 David Morales (david.morales4)
d22= DRODRI07 Domingo Rodriguez (domingo.rodriguez)
d23= DWASHA00 Daniel Washa (daniel.washa)
d24= EBROOK02 Earl Brooks (earl.brooks1)
d25= ECARRE00 Edelmira Carreon (edelmira.carreon)
Good evening,
I would like, using a macro to reverse the contents of a column, ex. in a column which is the 1st cell A1 whose name is "FirstCell", and the last cell A5 whose name is "LastCell":
1
2
3
4
5
and I get :
5
4
3
2
1
Thank you in advance for any suggestions.
Hi All,
I have my code for the most part working but unfortunately it duplicates and misses some data. I have tried to find the issue but I just can't see it and thought having some fresh eyes looking at it may be able to sort it out. Basically the source data is the orders which were sent on a particular delivery docket. The letters are not important so I have that data stripped out. I then were there were multiple orders on a line such as KC224601-12 needs to become 224601 and on the next line 224612.
Below is some sample data along with the results it gives me along with my desired results. This has not formatted properly but is also visible on the second sheet of the attached file.
HTML Code:
Source Data Actual Results Desired Results
KV224584 224584 224584
KV224585 224585 224585
KCV224587 224587 224587
ST224590 224590 224590
KC224593-5 224593-5 224593
KC224594 224594 224595
KC224596-8-9 224595 224594
KC224601-12 224596-8-9 224596
KV221101-11-2-5-28 224598 224598
KC221098-9 224601-12 224599
KCV221000 224599 224601
224612 224612
221101-11-2-5-28 221101
221111 221111
221112 221112
221115 221115
221098-9 221128
221128 221098
221099 221099
221000 221000
I have attached my spreadsheet for looking over. The part which I think is causing the error is in the code snip below which is the section which looks after the multiple orders section. This is just a snippet of the whole macro.
Code:
' If the connote has multiple orders insert a line beneath the current line and duplicate all values
If MultiOrderCheck = True Then
RightOrdersRemaining = RightOrders
x = 1
RightOrdersChecking::
For i = 1 To Len(RightOrders)
Select Case Mid(RightOrders, i, 1)
Case "-"
CurrentExtraLineOrder = Left(RightOrders, i - 1)
CurrentRightLength = Len(CurrentExtraLineOrder)
'Following messagebox is information only. Can remove once I confirm it functions
MsgBox ("CurrentExtraLineOrder = " & CurrentExtraLineOrder & " CurrentRightLength = " & CurrentRightLength)
RightOrders = Right(RightOrders, Len(RightOrders) - i) ' in preparation of the next order loop
' MsgBox ("currentextralineorder variable = " & CurrentExtraLineOrder & " New RightOrders = " & RightOrders)
LineOrder = Left(LineOrder, 6 - CurrentRightLength) & CurrentExtraLineOrder
ActiveCell.Offset(x, 0).EntireRow.Insert
ActiveCell.EntireRow.Copy ActiveCell.Offset(x, 0).EntireRow
Cells(r + x, "A") = LineOrder ' Paste the extra line order to the inserted line
x = x + 1 ' So that when the next order loops it gets inserted on the line beneath the last one
GoTo RightOrdersChecking ' This is so it starts to process from the start of the RightOrders
' variable again as otherwise data would be missed.
Case Else
' Not Required
End Select
Next i
'Processing of the last of RightOrders.
x = x + 1
LineOrder = Left(LineOrder, 6 - Len(RightOrders)) & RightOrders
ActiveCell.Offset(x, 0).EntireRow.Insert
ActiveCell.EntireRow.Copy ActiveCell.Offset(x, 0).EntireRow
Cells(r + x, "A") = LineOrder
End If
Any assistance or advice people can give would be much appreciated as it is starting to drive me nuts and I know it is probably a really simple thing I am missing.
I'm using Excel 2000 (so I can't lock ranges of cells through the menu bar), am not allowed by IT to use macros and will be creating this worksheet for people who really don't know Excel very well.
What I want to accomplish is to essentially create a calculator on a worksheet with a row of cells that will retain a formula even if the cell contents are deleted by the user using 'Clear Contents' or the Delete button.
Currently, erasing the cell contents this way will result in the formula also being erased.
This calculation task will only require one row of actual number inputting since the formula results will be hand-written onto a paper form. The user will then delete the cells and go on to the next paper form and enter the new numbers for that form.
Presently, I have A2:E2 with column labels, A3:E3 has the formulas (and I've made the row height very small so it doesn't accidently get deleted), A4:E4 is where the numbers from the paper form will be entered and D4 and E4 is where the formula will produce the calculations.
Now I just have to figure out how to lock the formula into A4:E4 so that the sheet users aren't constantly deleting the formula with the cell contents by the highly intuitive and vastly destructive Delete button or 'Clear Contents'.
I'm sure the ExcelGods must have envisioned this kind of thing but I can't figure it out since I'm only slightly more aware of Excel than the eventual inputters (but smart enough to come to you).
Heeeellpp (please)?
Betty
I know that is longwinded but what I am trying to do is basically
By entering 'A' in A:1 I want excel to automatically update B:1 with the contents of C:1
Is this possible?
Thanks in advance
Hi All,
New to this forum and am very new to VBA but am struggling through it! I have a spreadsheet that contains the following:
(Break 00:00:15.02) in one cell
(Lunch 00:00:30.04) in another cell
(Personal 00:00:12.51) in another cell ..... and so on.
What I would like to do is to move all the instances of Break to their own separate column and the same with Lunch and personal and then to delete the words break, Lunch etc just leaving the time. Is this possible using VBA?
Many thanks for any help
Gary
I get this error anytime I try to delete the contents of any cell (by clicking the DELETE key...Backspace works OK) OR if I try to the FORMAT->CLEAR CONTENTS option in any cell in columns D or P.
I do have a VBA code setup that involves those cells in those columns. Any idea how to fix this problem?
Here's the code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim CurrRow As Long
CurrRow = Target.Row
If Target.Column = 4 Then
If Target.Value = "" Then
If Cells(CurrRow, 2) = 408 Then Cells(CurrRow, 2) = 43
If Cells(CurrRow, 2) = 406 Then Cells(CurrRow, 2) = 398
ElseIf Target.Value 3030 And Cells(CurrRow, 2) = 408 Then Cells(CurrRow, 2) = 43
ElseIf Target.Value 8500 And Cells(CurrRow, 2) = 406 Then Cells(CurrRow, 2) = 398
End If
ElseIf Target.Column = 16 Then
If Target.Value = "" Then
If Cells(CurrRow, 14) = 408 Then Cells(CurrRow, 14) = 43
If Cells(CurrRow, 14) = 406 Then Cells(CurrRow, 14) = 398
ElseIf Target.Value 3030 And Cells(CurrRow, 14) = 408 Then Cells(CurrRow, 14) = 43
ElseIf Target.Value 8500 And Cells(CurrRow, 14) = 406 Then Cells(CurrRow, 14) = 398
End If
End If
End Sub
In the following formula (from SHEET2!) rather than Index just the ANSI150
array, i want to Index an array named in another cell that might be anyone of
a number of arrays names. eg I have both a ANSI150 and ANSI300 array and i
want to return the result based on which one of these is in another cell -
say B18 on the SHEET2!
=IF(A18>0,INDEX('Gasket
Calculation.xls'!ANSI150,MATCH(C18,Sheet1!$A$6:$A$26,),MATCH("iD",Sheet1!$A$6:$H$6,)),"")
|
|