+ Reply to Thread
Results 1 to 11 of 11

Replacing several cells + creating a keyboard shortcut

Hybrid View

  1. #1
    Registered User
    Join Date
    03-14-2008
    MS-Off Ver
    2010 (Home) + 365 (Home)
    Posts
    82

    Replacing several cells + creating a keyboard shortcut

    I've got a very very small request - I was hoping someone could donate 1 min of their time!

    i want this:

    if cell in column a = "abc def" then replace column j in the same row with "=otherWorksheet!a4"

    i need to do selective replacements - i will otherwise have to do the above manually - hundreds of times

    i need instructions on how to write the above code + how to make it into a macro that i could execute with a keyboard shortcut (or buttonpress)

    apologies if the above request is a cheeky one - i know i could do myself - but that might involve a few hours of putting my head down

    thanks in advance if anyone can help


    om
    Last edited by OM2; 07-13-2011 at 09:29 PM. Reason: Made an illegal post!

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Need help mass replacing several cells + creating a keyboard shortcut

    Create a button and assign the following procedure
    Sub OM2()
        Dim rCnt As Long, cl As Variant, ws As Worksheet
        Set ws = Sheets(1)
        rCnt = ws.Cells(Rows.Count, 1).End(xlUp).Row
        For Each cl In ws.Range(Cells(1, 1), Cells(rCnt, 1))
            If cl.Value = "abc def" Then
                Cells(cl.Row, 10).Value = "=otherWorksheet!a4"
            End If
        Next cl
    End Sub
    It should work (hopefully).
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    03-14-2008
    MS-Off Ver
    2010 (Home) + 365 (Home)
    Posts
    82

    Re: Need help mass replacing several cells + creating a keyboard shortcut

    mordred: thanks a million for the code
    it does exactly what i asked for
    but erm... i've only realised that my description wasn't good enough

    - i should have mentioned that i need to do wildcard searches - so any cell in column D containing the text "abc def" should have cell J in the same row replaced with "=abc!d2"

    - my experience of vba and excel is very very limited
    i don't even know how to open up the vba part and enter the code u gave!
    so, what i've done is created an empty macro and assigned a keyboard short cut
    then i've inserted the code u gave

    this worked ok with a dummy spreadsheet
    but the spreadsheet i need to use on has 4 different worksheets and the code wouldn't quite work

    let me know if u could suggest anything else

    thanks


    om

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Need help mass replacing several cells + creating a keyboard shortcut

    Quote Originally Posted by OM2 View Post
    mordred: thanks a million for the code
    it does exactly what i asked for
    but erm... i've only realised that my description wasn't good enough

    - i should have mentioned that i need to do wildcard searches - so any cell in column D containing the text "abc def" should have cell J in the same row replaced with "=abc!d2"

    - my experience of vba and excel is very very limited
    i don't even know how to open up the vba part and enter the code u gave!
    so, what i've done is created an empty macro and assigned a keyboard short cut
    then i've inserted the code u gave

    this worked ok with a dummy spreadsheet
    but the spreadsheet i need to use on has 4 different worksheets and the code wouldn't quite work

    let me know if u could suggest anything else

    thanks


    om
    Sorry I was reading too fast and only picked out certain words (in blue EDIT: [quotes don't show colours so look at the bold words]) and thought you tried uploaded a workbook, that's why my last post is the way it is. If you have a mock workbook made though, please upload it because it will remove guess work on my behalf.

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Need help mass replacing several cells + creating a keyboard shortcut

    Hi Omar, I would love to look at your workbook but you didn't upload it yet. Take your last post and click Edit and then Go Advanced and then select the paper clip button. follow the prompts after that.

    Regards

  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Need help mass replacing several cells + creating a keyboard shortcut

    Also, do you want the rows in column A And column D to be searched or just column D?

  7. #7
    Registered User
    Join Date
    03-14-2008
    MS-Off Ver
    2010 (Home) + 365 (Home)
    Posts
    82

    Re: Need help mass replacing several cells + creating a keyboard shortcut

    Quote Originally Posted by Mordred View Post
    Also, do you want the rows in column A And column D to be searched or just column D?
    just need column d searched of the first sheet 'Sales'

    i'll be off to bed in 5 min - it's nearly 3.30am where i am!

    u've been a star - thank u

  8. #8
    Registered User
    Join Date
    03-14-2008
    MS-Off Ver
    2010 (Home) + 365 (Home)
    Posts
    82

    Re: Need help mass replacing several cells + creating a keyboard shortcut

    thanks for the reply
    see attached to this post
    i've stripped all sensitive data

    so the code should go something like this:

    - if string "my special text " is contained in a cell in column D
    - then in column P of that same row, insert "=costPrice!d2"

    i will then run this code repeatedly and change "my special text " and "=costPrice!d2"

    i'm sure all of this sound like madness - but this will save me about 2 hours of work!

    let me know if u can suggest anything - or if u could add code to the spreadsheet - that would be amazing

    + if u could give a few basic instructions of how i can add myself, that would awesome as well

    THANK YOU!
    Attached Files Attached Files

  9. #9
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Need help mass replacing several cells + creating a keyboard shortcut

    Take a look at the workbook and let me know if its all good!


    Regards
    Attached Files Attached Files

  10. #10
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Need help mass replacing several cells + creating a keyboard shortcut

    LoL, it's late where you are! You should probably be sleeping. In saying that, I've spent a few late nights working out stuff in Excel so who am I to say?

  11. #11
    Registered User
    Join Date
    03-14-2008
    MS-Off Ver
    2010 (Home) + 365 (Home)
    Posts
    82

    Re: Replacing several cells + creating a keyboard shortcut

    i haven't had a chance to come back and say THANKS
    ur coding was a BIG help - couldn't have done it without u

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1