Consulting

Results 1 to 7 of 7

Thread: Solved: Moving cell values based on specific criteria

  1. #1
    VBAX Mentor
    Joined
    May 2010
    Location
    London
    Posts
    307
    Location

    Solved: Moving cell values based on specific criteria

    Hi All ,

    This below thread has been solved but I had a similar data scenario and replied to that instead of sending a new post. Because it seems solved that's why it didn't get any attention I'm afraid

    Could anyone help me on this please??

    http://www.vbaexpress.com/forum/showthread.php?t=43013

    Cheers
    Yeliz
    Sub Learning VBA()

    Do
    Practice Most Useful VBA Examples
    Loop Until Become an Expert in VBA

    End Sub

  2. #2
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    [VBA]Sub alex()
    Dim cell As Range
    Dim lr, lr2 As Long
    ActiveWorkbook.Sheets(1).Activate
    lr = Range("F" & Rows.Count).End(xlUp).Row
    lr2 = Range("G" & Rows.Count).End(xlUp).Row
    If lr2 > lr Then
    lr = lr2
    End If
    For Each cell In Range("F1:F" & lr)
    If cell.Value = "" And UCase(Right(cell.Offset(0, 1).Text, 4)) = "ROAD" Then
    cell.Value = cell.Offset(0, 1).Text
    cell.Offset(0, 1).ClearContents
    End If
    Next cell
    End Sub[/VBA]
    ------------------------------------------------
    Happy Coding my friends

  3. #3
    VBAX Mentor
    Joined
    May 2010
    Location
    London
    Posts
    307
    Location
    Thanks very much for your response I've run the script but nothing changed. Would you mind to see references G33-37-40-62 (in split) in attachment?

    PS: I've changed only Sheet object as Sheets(2) in below code, didn't touch rest of it.

    Cheers
    Yeliz

    Quote Originally Posted by CatDaddy
    [vba]Sub alex()
    Dim cell As Range
    Dim lr, lr2 As Long
    ActiveWorkbook.Sheets(1).Activate
    lr = Range("F" & Rows.Count).End(xlUp).Row
    lr2 = Range("G" & Rows.Count).End(xlUp).Row
    If lr2 > lr Then
    lr = lr2
    End If
    For Each cell In Range("F1:F" & lr)
    If cell.Value = "" And UCase(Right(cell.Offset(0, 1).Text, 4)) = "ROAD" Then
    cell.Value = cell.Offset(0, 1).Text
    cell.Offset(0, 1).ClearContents
    End If
    Next cell
    End Sub[/vba]
    Sub Learning VBA()

    Do
    Practice Most Useful VBA Examples
    Loop Until Become an Expert in VBA

    End Sub

  4. #4
    VBAX Mentor
    Joined
    May 2010
    Location
    London
    Posts
    307
    Location
    Sorry forgot the attachment in previous reply.
    Attached Files Attached Files
    Sub Learning VBA()

    Do
    Practice Most Useful VBA Examples
    Loop Until Become an Expert in VBA

    End Sub

  5. #5
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.

    you have trailing spaces in cells. trim function will remove excess spaces from cells.

    change
    [VBA]
    If cell.Value = "" And UCase(Right(cell.Offset(0, 1).Text, 4)) = "ROAD" Then[/VBA]

    to
    [VBA]
    If cell.Value = "" And UCase(Right(Trim(cell.Offset(0, 1).Text), 4)) = "ROAD" Then[/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  6. #6
    VBAX Mentor
    Joined
    May 2010
    Location
    London
    Posts
    307
    Location
    That's brilliant!!

    tHANKS VERy much mancubus as always

    PS: sorry for the late reply.

    Cheers
    Yeliz



    Quote Originally Posted by mancubus
    hi.

    you have trailing spaces in cells. trim function will remove excess spaces from cells.

    change
    [vba]
    If cell.Value = "" And UCase(Right(cell.Offset(0, 1).Text, 4)) = "ROAD" Then[/vba]
    to
    [vba]
    If cell.Value = "" And UCase(Right(Trim(cell.Offset(0, 1).Text), 4)) = "ROAD" Then[/vba]
    Sub Learning VBA()

    Do
    Practice Most Useful VBA Examples
    Loop Until Become an Expert in VBA

    End Sub

  7. #7
    Nice, very useful!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •