+ Reply to Thread
Results 1 to 4 of 4

Do Copy Paste on different Cell, when type "OK",Macro newbie, Help!

Hybrid View

  1. #1
    Registered User
    Join Date
    11-12-2015
    Location
    Surabaya, Indonesia
    MS-Off Ver
    MS 365 (Windows 11 64-bit)
    Posts
    84

    Do Copy Paste on different Cell, when type "OK",Macro newbie, Help!

    Hi All,

    linkback : http://www.mrexcel.com/forum/excel-q...wbie-help.html

    I Have this problem. I want to when type OK, it'll copy and paste it as value based on its row. and select other cell
    like this pic below.

    so when i type OK :
    - on D5, it'll copy F5:H5, and paste to J5:L5, and then select cell N5
    - on D6, it'll copy F6:H6, and paste to J6:L6, and then select cell N6
    .
    .
    .
    and so on until D14.

    right now i'm using this code below on worksheet change, but it's too long, and kinda evaluate from first - end every time run the code... someone help me?

    i've also upload the file http://s000.tinyupload.com/?file_id=...70715604698398

    thanks a lot for the help
    warm regards,

    Adrian

    Capture.JPG

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Range("D5").Value = "OK" Then
        Application.EnableEvents = False
        Range("F5:H5").Copy
        
        Sheets("Sheet1").Range("J5:L5").PasteSpecial xlPasteValues
        Application.CutCopyMode = False
        
        Range("N5").Select
    Else
            
    End If
    
    Application.EnableEvents = True
    
    '-----------------------------------------------------------
    If Range("D6").Value = "OK" Then
        Application.EnableEvents = False
        Range("F6:H6").Copy
        
        Sheets("Sheet1").Range("J6:L6").PasteSpecial xlPasteValues
        Application.CutCopyMode = False
        
        Range("N6").Select
    Else
            
    End If
    
    Application.EnableEvents = True
    
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Do Copy Paste on different Cell, when type "OK",Macro newbie, Help!

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Count > 1 Then Exit Sub    ' this stops code error if more than one cell is changed at once
    
        If Not Application.Intersect(Target, Me.Range("D5:D14")) Is Nothing Then    ' indicates the Target range
    
            If Target = "OK" Then
    
                Range(Cells(Target.Row, "J"), Cells(Target.Row, "L")).Value = Range(Cells(Target.Row, "F"), Cells(Target.Row, "H")).Value
    
            End If
    
        End If
    
    End Sub
    See here
    http://www.excelforum.com/tips-and-t...et-events.html

  3. #3
    Registered User
    Join Date
    11-12-2015
    Location
    Surabaya, Indonesia
    MS-Off Ver
    MS 365 (Windows 11 64-bit)
    Posts
    84

    Re: Do Copy Paste on different Cell, when type "OK",Macro newbie, Help!

    Quote Originally Posted by Special-K View Post
    in J5
    =IF(D5="OK",F5,"")
    copy down and along as far as L14
    Hi Special - K,

    I want to prevent contain function, and automatically paste as value, and DavesExcel have just answered my question.

    Quote Originally Posted by davesexcel View Post
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Count > 1 Then Exit Sub    ' this stops code error if more than one cell is changed at once
    
        If Not Application.Intersect(Target, Me.Range("D5:D14")) Is Nothing Then    ' indicates the Target range
    
            If Target = "OK" Then
    
                Range(Cells(Target.Row, "J"), Cells(Target.Row, "L")).Value = Range(Cells(Target.Row, "F"), Cells(Target.Row, "H")).Value
    
            End If
    
        End If
    
    End Sub
    See here
    http://www.excelforum.com/tips-and-t...et-events.html
    Hi DavesExcel,

    Thanks a lot for the code. it works perfectly. 1 request remained, how to automatically select cell in column N in row where i type OK?

    warm regards,

    Adrian

  4. #4
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,076

    Re: Do Copy Paste on different Cell, when type "OK",Macro newbie, Help!

    in J5
    =IF(D5="OK",F5,"")
    copy down and along as far as L14
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 01-22-2016, 09:21 AM
  2. "Coloring macro" and a "copy if cell contents are .." macro are interfering
    By dreddster in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2015, 08:30 AM
  3. Short "Basic" Macro to copy and paste formulas "N" times.
    By gradyhawks in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-09-2014, 02:34 PM
  4. [SOLVED] want to edit recorded macro code or copy a cell with formula and paste it down to "x" cell
    By bmbalamurali in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 10-25-2013, 04:57 PM
  5. [SOLVED] Need to modify the Paste function of this VBA Macro from "Paste" to "Paste Special Values"
    By zicitron in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-04-2013, 03:44 AM
  6. [SOLVED] Macro: always copy/paste text from cell "I" (on the same row the was cell selected)
    By rampal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2013, 03:43 AM
  7. How can i copy value from "HTMLText"(EMBED("Forms.HTML:Text","")),using Macro
    By andrewyang in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2010, 12:47 AM

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