简体   繁体   中英

combine different cells to same row

I want each record on the same row:

Row 1 Column 1: Parcel Number,  Row 1 Column 2: Owner Name, Row 1 Column 3: Address

SAMPLE :

Parcel Record 21033540290000 Owner Doe, John M, SR. & Jane H; TRS Address 2116 W Wall St Parcel Record 21033540450000 Owner Brown, MARSHA & GREEN, MARIE; JT Address 2131 W Harvard Ave Parcel Record 21033230450000 Owner Smith, MICHELLE K Address 4281 S Yale Ave

I would like the format to be on the same row with 3 columns:

21033540290000  Doe, John M, SR. & Jane H; TRS          2116 W Wall St
21033540450000  Brown, MARSHA & GREEN, MARIE; JT        2131 W Harvard Ave
21033230450000  Smith, MICHELLE K                       4281 S Yale Ave

Then delete the Owner and Address rows after the data is copied to the same row as the Parcel number.

Have recorded a macro, but have problem looping & referencing cells and rows. Sub FormatRows() ' ' FormatRows Macro ' Formats to same row ' ' Keyboard Shortcut: Ctrl+f

Range("B1").Select
Selection.Cut
Range("A1").Select
ActiveSheet.Paste
Range("B2").Select
Selection.Cut
Range("B1").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("C1").Select
ActiveSheet.Paste
Rows("2:2").Select
Selection.Delete Shift:=xlUp
Selection.Delete Shift:=xlUp
Range("B2").Select
Selection.Cut
Range("A2").Select
ActiveSheet.Paste
Range("B3").Select
Selection.Cut
Range("B2").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("C2").Select
ActiveSheet.Paste
Rows("3:3").Select
Selection.Delete Shift:=xlUp
Selection.Delete Shift:=xlUp
Range("B3").Select
Selection.Cut
Range("A3").Select
ActiveSheet.Paste
Range("B4").Select
Selection.Cut
Range("B3").Select
ActiveSheet.Paste
Range("B5").Select
Selection.Cut
Range("C3").Select
ActiveSheet.Paste
Rows("4:4").Select
Selection.Delete Shift:=xlUp
Selection.Delete Shift:=xlUp
Range("B4").Select

End Sub

' How can I get this to loop thru a couple thousand rows?

Thank you!

This would require string processing

Step 1: Find the number part:

Dim strTemp As String
Dim strChar As String
strTemp = "Parcel Record 21033540290000 Owner Doe, John M, SR. & Jane H; TRS Address 2116 W Wall St "


flag = True
i = 1
On Error GoTo lblEnd:
While flag = True
    strChar = Strings.Mid(strTemp, i, 1)
    If IsNumeric(strChar) Then
        'your code here
    End If
    i = i + 1
Wend

lblEnd:
Err.Clear

Step 2: Find "," and ":". Just change the if part of the previous code:

 If strChar = "," Then
     'your code here
 End If

and this:

 If strChar = ":" Then
     'your code here
 End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM