+ Reply to Thread
Results 1 to 7 of 7

VBA Help with a Copy & Paste of Targeted Columns

  1. #1
    Registered User
    Join Date
    07-29-2019
    Location
    Los Angeles. Ca
    MS-Off Ver
    2013
    Posts
    38

    Talking VBA Help with a Copy & Paste of Targeted Columns

    Hi VBA Gurus,

    I have created a subroutine that copies targeted static columns from one worksheet called "Copy Sheet" to the "Master" worksheet. I have two issues with this For LOOP routine:

    1). It does not seem to end, I think its looping back to the beginning. I need to know how to stop the routine at the end of the last copy, paste scenario
    2). I need a message box that states "Copy and Paste Completed" once the subroutine is completed.

    Can anyone help me with the below? Many Thanks! :)


    Public Sub CopyColumnsSourceToTarget()
    'Worksheets("Master").Activate
    'Dim sheetname As String


    Dim sourceBook As Workbook
    Dim targetBook As Workbook
    Dim sourceSheet As Worksheet
    Dim targetSheet As Worksheet
    Dim lrow As Integer
    Dim i As Integer


    'Must have two tabs with data in both the Master and DHL Inbound - DAO All Americas. Maybe message box here to ensure both tabs with data ?


    ' Set up the sheets



    'Get lrow
    lrow = Worksheets("Master").Range("C1").End(xlDown).Row



    'Code to Copy
    For i = 2 To lrow
    If Worksheets("Master").Cells(i, 33).Value = "" Then
    Worksheets("Master").Cells(i, 33).Value = Worksheets("Copy Sheet").Cells(i, 29).Value
    End If

    If Worksheets("Master").Cells(i, 38).Value = "" Then
    Worksheets("Master").Cells(i, 38).Value = Worksheets("Copy Sheet").Cells(i, 33).Value
    End If

    If Worksheets("Master").Cells(i, 39).Value = "" Then
    Worksheets("Master").Cells(i, 39).Value = Worksheets("Copy Sheet").Cells(i, 34).Value
    End If

    If Worksheets("Master").Cells(i, 40).Value = "" Then
    Worksheets("Master").Cells(i, 40).Value = Worksheets("Copy Sheet").Cells(i, 35).Value
    End If

    If Worksheets("Master").Cells(i, 45).Value = "" Then
    Worksheets("Master").Cells(i, 45).Value = Worksheets("Copy Sheet").Cells(i, 38).Value
    End If

    If Worksheets("Master").Cells(i, 46).Value = "" Then
    Worksheets("Master").Cells(i, 46).Value = Worksheets("Copy Sheet").Cells(i, 39).Value
    End If

    Next i



    ' Done - small clean up

    End Sub

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: VBA Help with a Copy & Paste of Targeted Columns

    Try so maybe.
    Please Login or Register  to view this content.
    Experience trumps academics every day of the week and twice on Sunday.

  3. #3
    Registered User
    Join Date
    07-29-2019
    Location
    Los Angeles. Ca
    MS-Off Ver
    2013
    Posts
    38

    Re: VBA Help with a Copy & Paste of Targeted Columns

    thanks Jolivanes - Let me give this a try ...! I will let you know!

  4. #4
    Registered User
    Join Date
    07-29-2019
    Location
    Los Angeles. Ca
    MS-Off Ver
    2013
    Posts
    38

    Re: VBA Help with a Copy & Paste of Targeted Columns

    Hi Jolivanes, BTW, why offset formula? thank you!

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: VBA Help with a Copy & Paste of Targeted Columns

    You don't need to use Offset. You can use the actual cell addresses if you want.
    It's just one way of doing it.

  6. #6
    Registered User
    Join Date
    07-29-2019
    Location
    Los Angeles. Ca
    MS-Off Ver
    2013
    Posts
    38

    Re: VBA Help with a Copy & Paste of Targeted Columns

    Hi Jolivanes - Thanks. Does the offset refer to the Copy Values columns? This is interesting because I have not thought of this approach. Thank you.

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: VBA Help with a Copy & Paste of Targeted Columns

    No, they all reference Cell(i, 33)

+ 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: 12-20-2019, 01:49 AM
  2. [SOLVED] Help triggering macro off paste making targeted cell a hyperlink
    By JayBiTech in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-23-2019, 11:41 PM
  3. Replies: 2
    Last Post: 11-15-2015, 01:33 AM
  4. [SOLVED] Return targeted columns from an array of columns
    By tuna666 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-10-2013, 06:50 AM
  5. Simple data entry form above the targeted columns.
    By mrmikepan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-03-2013, 05:34 PM
  6. Replies: 5
    Last Post: 12-01-2012, 06:34 PM
  7. 2 Macro's: only vertical copy/paste action and copy-paste 14 columns to the right.
    By vdongen in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-08-2010, 10:34 AM

Tags for this Thread

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