+ Reply to Thread
Results 1 to 9 of 9

An "adding" PASTE and a CELL update

Hybrid View

drgkt An "adding" PASTE and a CELL... 01-20-2017, 04:37 AM
drgkt Re: An "adding" PASTE and a... 01-20-2017, 04:09 PM
vichopalacios Re: An "adding" PASTE and a... 01-20-2017, 05:34 PM
drgkt Re: An "adding" PASTE and a... 01-20-2017, 07:03 PM
drgkt Re: An "adding" PASTE and a... 01-20-2017, 08:24 PM
drgkt Re: An "adding" PASTE and a... 01-22-2017, 01:45 AM
drgkt Re: An "adding" PASTE and a... 01-22-2017, 03:05 AM
vichopalacios Re: An "adding" PASTE and a... 01-23-2017, 09:13 AM
vichopalacios Re: An "adding" PASTE and a... 01-23-2017, 08:30 AM
  1. #1
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    An "adding" PASTE and a CELL update

    Hi

    I need 2 macros:

    1. An ordinary macro that would copy values only of G7:G29 pasting them to H7:H29 BUT adding the G value to the H value.
    For example, H11 would become 223.74.

    2. An automatic sheet changing macro that when a value (numeric) is entered in J7:J29, that value would be subtracted from either the value in H or I, same row, which ever is filled, and the value in H or I would be updated.
    (H and I will NEVER have values on the SAME row).
    The value entered in J cannot be greater than the value entered in H or I.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by drgkt; 01-20-2017 at 04:40 AM.

  2. #2
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: An "adding" PASTE and a CELL update

    Anyone please...

  3. #3
    Valued Forum Contributor
    Join Date
    08-07-2014
    Location
    Quito, Ecuador
    MS-Off Ver
    Excel 2016 & 365, Windows 10
    Posts
    511

    Re: An "adding" PASTE and a CELL update

    1.-

    Sub AddColumns()
    Dim Sht As Worksheet
    Set Sht = ActiveSheet
    For i = 7 To 29
        Sht.Cells(i, 8).Value = Sht.Cells(i, 7).Value + Sht.Cells(i, 8).Value
    Next i
    End Sub
    2.-

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim myRow As Long, myCol As Long
    Debug.Print ActiveSheet.Name
       If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
       Debug.Print Target.Address
            If Not Intersect(Target, Range("J7:J29")) Is Nothing Then
                If IsNumeric(Target) Then
                    myRow = Target.Row
                        If Cells(myRow, 8).Value = "" Then
                            myCol = 9
                        Else
                            myCol = 8
                        End If
                           On Error Resume Next
                                Application.EnableEvents = False
                                    If Target.Value > Cells(myRow, myCol).Value Then
                                        MsgBox "Value is grather than H or I"
                                        Target.Value = ""
                                        Exit Sub
                                    Else
                                        Cells(myRow, myCol).Value = Cells(myRow, myCol).Value - Target.Value
                                    End If
                                Application.EnableEvents = True
                           On Error GoTo 0
                End If
            End If
    End Sub
    Last edited by vichopalacios; 01-20-2017 at 05:37 PM.
    Barriers are there for those who don't want to dream

  4. #4
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: An "adding" PASTE and a CELL update

    Thank you for helping me achieve this!
    edit: Thank you for achieving this for me!

    Re: sheet code

    On testing, I saw once the message that the value was greater than H or I, not seeing it any more nor the values are reduced by J
    Attached Files Attached Files
    Last edited by drgkt; 01-20-2017 at 07:13 PM.

  5. #5
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: An "adding" PASTE and a CELL update

    Re Macro 1.

    To get rid of zeros I changed formula in G7:G29 to "=IF(E7="√";"";IF(D7-F7=0;"";D7-F7))"
    Now I am getting RunTime ERROR 13: Type mismatch
    Sht.Cells(i, 8).Value = Sht.Cells(i, 7).Value + Sht.Cells(i, 8).Value


    p.s. If G is blank and H is blank H becomes zero instead of be left blank
    Last edited by drgkt; 01-22-2017 at 01:46 AM.

  6. #6
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: An "adding" PASTE and a CELL update

    Ok. Despite the minor details above,

    Macro 1: Usable as is, and optionally formatting zero values to be invisible.

    HOWEVER

    Macro 2: Is not working as supposed to. Sometimes it gives the message "Value is grater than H or I", sometimes it is not, BUT FAILS to add the value to either H or I.


    Someone to take a look in the code please!

  7. #7
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: An "adding" PASTE and a CELL update

    Deleted this post
    Last edited by drgkt; 01-22-2017 at 03:10 AM.

  8. #8
    Valued Forum Contributor
    Join Date
    08-07-2014
    Location
    Quito, Ecuador
    MS-Off Ver
    Excel 2016 & 365, Windows 10
    Posts
    511

    Re: An "adding" PASTE and a CELL update

    Hi @ drgkt

    Macro 2: Is not working as supposed to. Sometimes it gives the message "Value is grater than H or I", sometimes it is not, BUT FAILS to add the value to either H or I.
    I think I found the bug.
    by sure, with the previous code, after you saw the "Value is greater than H or I" message, the worksheet started to show a weird performance.
    it was because we ended the sub leaving "Application.EnableEvents = False"
    now, try with this please.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim myRow As Long, myCol As Long
       If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
            If Not Intersect(Target, Range("J7:J29")) Is Nothing Then
                If IsNumeric(Target) Then
                    myRow = Target.Row
                        If Cells(myRow, 8).Value <> "" Then
                            myCol = 8
                        ElseIf Cells(myRow, 9).Value <> "" Then
                            myCol = 9
                        Else
                            Exit Sub
                        End If
                        On Error Resume Next
                         Application.EnableEvents = False
                             If Target.Value > Cells(myRow, myCol).Value Then
                                 MsgBox "Value is grather than H or I"
                                 Target.Value = ""
                                 Application.EnableEvents = True
                                 Exit Sub
                             Else
                                 Cells(myRow, myCol).Value = Cells(myRow, myCol).Value - Target.Value
                             End If
                         Application.EnableEvents = True
                        On Error GoTo 0
                End If
            End If
    End Sub

  9. #9
    Valued Forum Contributor
    Join Date
    08-07-2014
    Location
    Quito, Ecuador
    MS-Off Ver
    Excel 2016 & 365, Windows 10
    Posts
    511

    Re: An "adding" PASTE and a CELL update

    Hi @ drgkt

    My answers take sometimes longer than you may like
    I'm sory, I'm not a 24/7 follower of this site, I just come here from time to time, when I'm free, and feel the liking.

    for macro#1
    If you want not to do anything when there is nothing in H(i), then you can change to this:

    Sub AddColumns()
    Dim Sht As Worksheet
    Set Sht = ActiveSheet
    For i = 7 To 29
        If Sht.Cells(i, 8).Value <> "" Then
            Sht.Cells(i, 8).Value = Sht.Cells(i, 8).Value - Sht.Cells(i, 7).Value
        End If
    Next i
    End Sub
    for macro# let me check, I think I understand your point.

+ 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. Update Macro to search column Bfor "Fail" and "Exception"
    By programct in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2014, 02:32 PM
  3. solution for the blank cell using the IF function
    By ragnaedge in forum Excel General
    Replies: 4
    Last Post: 08-23-2013, 11:03 AM
  4. [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
  5. Replies: 0
    Last Post: 11-20-2012, 10:22 AM
  6. What is Error "Method "Paste" of object "_Worksheet" failed?
    By vat in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-17-2006, 04:10 PM
  7. Replies: 1
    Last Post: 01-30-2006, 06:10 PM

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