+ Reply to Thread
Results 1 to 14 of 14

Loop?

  1. #1
    Registered User
    Join Date
    04-23-2006
    Posts
    15

    Arrow Loop?

    The code below works once. I'd like it to run anytime the value changes. I assume this requires the use of a loop.

    I have no clue how loops work. Anybody feel like helping me out?

    Thanks.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,996
    After the addition of the line indicated, the code will copy the last used cell of Col D on the first sheet to cell B3 on the other sheet. Was that your intent?


    PHP Code: 
    Private Sub Worksheet_Change(ByVal Target As Range)
        
    Application.ScreenUpdating False
        Range
    ("D48").End(xlDown).Copy
        Sheets
    ("Financial Summary").Activate
        ActiveSheet
    .Cells(32).Select
        Selection
    .PasteSpecial paste:=xlPasteValuesOperation:=xlNoneSkipBlanks _
        
    :=FalseTranspose:=False
        Sheets
    ("Checking Transaction History").Activate
        Application
    .CutCopyMode False     "<-------- added to cancel out of the copy/paste operation.  "
    Application.ScreenUpdating True

    End Sub 
    Ben Van Johnson

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    where is your target range?
    This one works if A1 changes



    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    04-23-2006
    Posts
    15

    Arrow

    Yes that is exactly my intent. It is working, however it only copy's the last used cell from Colum D to B3 on the other sheet one time.

    I am looking for it to copy and paste as appropriate every time the last used cell is added/updated/changed.

    Adding your suggested line of code seems to have no effect: (still only works once)

    Please Login or Register  to view this content.

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    Quote Originally Posted by superspiker
    Yes that is exactly my intent. It is working, however it only copy's the last used cell from Colum D to B3 on the other sheet one time.

    I am looking for it to copy and paste as appropriate every time the last used cell is added/updated/changed.

    Adding your suggested line of code seems to have no effect: (still only works once)

    Please Login or Register  to view this content.

    You didn't answer the question

    What range do you want the code to activate??

  6. #6
    Registered User
    Join Date
    04-23-2006
    Posts
    15
    I'd like the macro to execute whenever the last used cell in colum D is added/updated/changed.

    Does that help answer the question?

  7. #7
    Registered User
    Join Date
    11-29-2006
    Posts
    6
    Superspiker,
    Worksheet_Change is supposed to work everytime there is a change in worksheet.

    I frankly do not see any problem with the code.

    I am assuming though that as a result of the copy and paste operations done there are no changes hapening on your source cells. Because if this happens then you will go into a loop and as per my understanding excel comes out of this loop automatically after some 250 times.

    I would check the following:
    1. See if there are any static variables else where in the code. if for e.g. you have a static integer which is hitting the max end of its range
    2. See if there are any changes happening in the source sheet as a result your copy and paste operations.

    Not sure if i have solved your problem.

  8. #8
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    here you go



    Range(("D48"), Selection.End(xlDown)).Copy


    Sorry abot that

  9. #9
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    whenever there is a change in column D the code executes

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-23-2006
    Posts
    15

    Exclamation

    Thanks for all the quick responses.

    Well Shoot. It's still not workin.

    Any more ideas?

    Please Login or Register  to view this content.

  11. #11
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    go to this site to find out where the worksheet module is

    http://www.contextures.com/xlvba01.html#Workbook

  12. #12
    Registered User
    Join Date
    04-23-2006
    Posts
    15

    Lightbulb

    I was thinking about taking a different approach.

    Can someone post code that would make the last used cell of Colum D on the active sheet equal to B3 on the other sheet?

    Thanks.

  13. #13
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    This should work

    Please Login or Register  to view this content.

    change sheet names as required

  14. #14
    Registered User
    Join Date
    04-23-2006
    Posts
    15

    Talking

    Thank you davesexcel!

    This is exactly what I was looking for. It works perfectly.

    Please Login or Register  to view this content.

+ 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