Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pull 3 data elements from one row and place in other cells - EXCEL

Status
Not open for further replies.

FrenchCadeau

Programmer
Jan 8, 2011
1
US
I have a worksheet that has several thousand rows and I need to extract the numbers, into separate cells, that are to the far right of the row and the length is different for each row. There are three numbers that I want to pull into separate cells.
Example of the data:
24 P1-SAC-LEV4 X(04). 48 51 4
21 ORG-STRE-CODE-AGCY X 101 102 2

20 I-CD 5 34 30

However, every once in a while the last number contains a "P"
Basically starting at the first cell to the right of the data row, I would like to have 48 on the row starting with 24 and 101 on the row starting with 21 and 5 on the starting with 20
Next cell would be 51 for row starting with 24, 102 for the row starting with 21 and 34 for the last example row
Third and final cell, self explanatory, however, I want to drop the "P" in the final row so I only have 30 as the value.
I know this is asking allot but I wouldn't even know where to start or even know if this is possible. Thank you very much.
 
I think you need a macro (VBA) to solve this.
If I have correctly identified your requirements then this should work.
Code:
Sub Macro1()
'
'Select the first column of the rows to be processed before running this macro
Dim myCell As Range
For Each myCell In Selection
    Range(myCell.End(xlToRight), myCell.End(xlToRight).Offset(0, -2)).Cut
    On Error Resume Next
    myCell.Offset(0, 1).Insert Shift:=xlToRight
    On Error GoTo 0
Next myCell
Selection.Offset(0, 3).EntireColumn.Replace What:="p", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
End Sub
If you have any queries then you should really post in Forum707

Gavin
 



Also, when you post examples, please use the TT MonoSpaced Text using Process TGML code. Search this page for the Process TGML link.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top