+ Reply to Thread
Results 1 to 10 of 10

Macro limits the copying

  1. #1
    Registered User
    Join Date
    10-06-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    37

    Macro limits the copying

    Hi again,

    I need help here too, I have this table: examp.xlsx and I'm using a macro that copy and paste data to another spreadsheet with this code:

    Sub Save()

    Dim i&
    With Sheets("Plan1").Range("B6").CurrentRegion
    i = .Rows.Count - 1
    With .Offset(1).Resize(i)
    Union(.Columns(1).Resize(, 10), .Columns(12), .Columns(14).Resize(, 3)).Copy
    Sheets("Plan2").Cells(Rows.Count, 3).End(xlUp)(2).PasteSpecial xlPasteAllExceptBorders
    End With
    End With
    With Sheets("Plan2").Cells(Rows.Count, 2).End(xlUp)(2).Resize(i)
    .FormulaR1C1 = "=ROW(RC[-2])-6"
    .Value = .Value
    End With
    Application.CutCopyMode = False

    End Sub
    However I want to limit the functionality of this macro because I dont want this macro copy rows that have no data in columns C6, D6, E6, F6, G6, H6, J6, K6, M6, O6, in between rows 7 to 20. But can copy if there is no data in B6, I6, L6, N6, P6, Q6 in between rows 7 to 20.
    So if there is no data in these columns, a warning appears saying "Unable to copy. Complete the columns". Does anyone know how to do this?

    Are trying to help me on this forum as well: http://www.vbaexpress.com/forum/show...ng-of-the-data

    Cheers!
    Last edited by carapins; 10-18-2013 at 05:08 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro limits saving of the data

    I do not see any line of the code which deals with saving, but this line errors.

    Please Login or Register  to view this content.
    As you have a single row, you need to remove the minus from 1

    i = .Rows.Count[/CODE]

  3. #3
    Registered User
    Join Date
    10-06-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Macro limits saving of the data

    The code is right. If you create a macro with that code and use for example this data on table: try.xlsx the data is save correctly as I want

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro limits saving of the data

    Yes, the code works on the latest attached as you have increased the no of rows, but still there is no save line, so I do not know what the issue is.

  5. #5
    Registered User
    Join Date
    10-06-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Macro limits saving of the data

    The term "save" may not be correct ... what I want is to copy and paste data but if there is no data in the columns that I mentioned then is not able to copy and paste

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro limits saving of the data

    Carapins,
    First of all, you need to wrap your code with tags as per forum's rule.
    Second, if you have a code and want to amend it, you need to attach it with the sample, so the person who looks on the attached could easily find it.
    I have not got error when I run it. You need to show me what error you are getting or, which part of the code do you want to change.

  7. #7
    Registered User
    Join Date
    10-06-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Macro limits saving of the data

    I know that there is no error in the code. But I want the code doesnt work if the columns that I mentioned didn't have data. I want to limit the functionality of this macro because I dont want this macro copy rows that have no data in columns I mentioned. What you dont understand here?

  8. #8
    Registered User
    Join Date
    10-06-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Macro limits the copying

    I am trying to do in this way to not copy the column C (C7:C20) if there is no data:

    Please Login or Register  to view this content.
    But doesn't work...

  9. #9
    Registered User
    Join Date
    10-06-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Macro limits saving of the data

    Something better...

    Please Login or Register  to view this content.
    But it was necessary to write a code to determine first if there is data in rows 7,8,9,10,11,12,13...20 and if there is data then just check in these rows if there are cells without data. Anyone knows?

    Cheers!

  10. #10
    Registered User
    Join Date
    10-06-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Macro limits the copying

    Up...

    Some help please, I'll need this done...

+ 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. Macro to find value between two limits for a given condition
    By DamirDz in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-26-2013, 04:19 PM
  2. [SOLVED] Beginner Here: Saving data using macro in new rows.
    By aleem5 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2013, 12:34 AM
  3. Macro for saving cell data to another sheet
    By aknsms in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-24-2012, 02:23 PM
  4. saving, deleting data, macro
    By burgerboy2k6 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2007, 10:01 PM
  5. [SOLVED] Saving Data In a Macro
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-29-2006, 06:55 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