+ Reply to Thread
Results 1 to 17 of 17

how to exclude a column from copy and past in vba

  1. #1
    Registered User
    Join Date
    04-28-2016
    Location
    usa
    MS-Off Ver
    2007
    Posts
    48

    how to exclude a column from copy and past in vba

    Dear Sir,

    I have this VBA

    Sub Button7_Click()
    Application.ScreenUpdating = False
    Sheets("resturant").Range("A6:j600000").AdvancedFilter Action:= _
    xlFilterCopy, CriteriaRange:=Range("A1:C2"), CopyToRange:=Range( _
    "A6:j600000"), Unique:=False

    Application.ScreenUpdating = True

    End Sub

    I need to filter and copy range A6:J600000 BUT I NEED TO EXCLUDE CELL "G" FROM FILTERING AND COPYING AND PASTING, BECAUSE I HAVE MY OWN FORMULA IN CELL "G" OF THE COPY TO RANGE and do not need the value of this cell.


    Please advice kindly
    Last edited by markswan111; 01-23-2023 at 06:34 PM.

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,220

    Re: how to exclude a cell from copy and past in vba

    Can you attach a workbook with a few rows of data to see the layout of the data, because the code raises some questions.

    Artik

  3. #3
    Registered User
    Join Date
    04-28-2016
    Location
    usa
    MS-Off Ver
    2007
    Posts
    48

    Re: how to exclude a cell from copy and past in vba

    hello, many thanks for your help, I have included the workbook

    again I just need to filter and copy & paste this range a6:j60000 but also omitting cell ( G ) from copying and pasting, is there such a command that I can add to this Range("A6:j600000") to disable copying and pasting of ONLY (G) cell in this Range("A6:j600000") ?

    The reasoner for doing so, is that I need to have my own formula in Cell G in the balance sheet, thus stopping this vba from pasting into it and erasing my formulas, but also I need all the other cell values form a6:j60000 to be copied and pasted.

    Many thanks

    Mark Swan
    Attached Files Attached Files
    Last edited by markswan111; 01-22-2023 at 06:07 PM. Reason: uploading workbook

  4. #4
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: how to exclude a cell from copy and past in vba

    My dear @Lewis Clark:
    I look at your workbook and I look at your VBA code and I come to one conclusion: things will never work for you this way. Let's analyze together:

    a) You have defined the criteria range as A1:C2 but C1:C2 is a merged cell. Conclusion: this can't work like this.

    b) The range A1:B2 is empty: How do you want us to know which criteria you want to apply?

    c) The VBA code you have developed wants to copy the extract range over the data range: Impossible!
    Last edited by beyond Excel; 01-22-2023 at 07:18 PM.
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  5. #5
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: how to exclude a cell from copy and past in vba

    I am uploading to the Forum what you should have uploaded: only what is necessary.

    After:
    a) Complete the 7 data rows with more or less real (or invented) data.

    b) Show us in the criteria range a set of actual criteria you would use.

    c) Upload said workbook for us to see.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-28-2016
    Location
    usa
    MS-Off Ver
    2007
    Posts
    48

    Re: how to exclude a cell from copy and past in vba

    Dear Sir,

    we have miss understanding,



    a) You have defined the criteria range as A1:C2 but C1:C2 is a merged cell. Conclusion: this can't work like this. ( c1:c2 are not merged together) the criteria range is on the balance sheet, you are looking at the suppliers sheet of which the vba extract data from to balance sheet.

    b) The range A1:B2 is empty: How do you want us to know which criteria you want to apply?

    again you are looking at the suppliers sheet of which I enter data, the range b2 is not empty on the balance sheet, of which I enter the criteria I want.
    and my vba is fully working as is.

    c) The VBA code you have developed wants to copy the extract range over the data range: Impossible!

    No again you haven't seen the balance sheet in which I enter the criteria I want and extract data from suppliers sheet to balance sheet.


    the vba in the workbook I sent you is fully working and extracting info.


    my question is simple (can I use this vba, without extracting the cell G data in suppliers sheet? in other words exclude it from the range, while being able to extract all the other data in the range cells?


    this is simply my question, the vba is working in the workbook I posted.

    Many thanksvba.xlsb
    Last edited by markswan111; 01-23-2023 at 01:28 AM. Reason: uploading workbook

  7. #7
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: how to exclude a cell from copy and past in vba

    My dear markswan111:

    a) 'G' is not a cell: It's a column!... So we're talking about column G, okay?

    b) In addition to column G you have formulas in column H.

    c) When we use the advanced filter, the formulas are ALWAYS lost and only the values are copied.

    d) And if we applied two advanced filters: one copying the data from columns A:F and the other copying the data from columns I:J you would see that in columns G and H you would have nothing and you would have to add the formulas to them.

    e) The following solution does a single filtering and then adds the formulas:

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: how to exclude a cell from copy and past in vba

    I forgot to tell you to take a close look at the above VBA code:

    a) Every time a range of cells is referenced, said range is preceded by the indication of the sheet to which said range belongs.

    b) In this way, any type of doubt is avoided and the original confusion is not given place.

    c) And another advantage is that you can have any sheet selected and the code will work the same.

  9. #9
    Registered User
    Join Date
    04-28-2016
    Location
    usa
    MS-Off Ver
    2007
    Posts
    48

    Re: how to exclude a cell from copy and past in vba

    My Dearest beyond excel, many thanks for your patience and help, and sorry for confusing you by naming G Column a cell


    you said :

    d) And if we applied two advanced filters: one copying the data from columns A:F and the other copying the data from columns I:J you would see that in columns G and H you would have nothing and you would have to add the formulas to them.

    this exactly what I need ( you would see that in columns G and H you would have nothing and you would have to add the formulas to them) I want to add the formulas manually to G and H columns, thus I need nothing copied to them

    Can I have a simple VBA to stop copying into columns G&H? and I could then enter my own formulas in there by altering my original VBA to just stop copying into columns G&H

    this is my original vba

    ub Button7_Click()
    Application.ScreenUpdating = False
    Sheets("resturant").Range("A6:j600000").AdvancedFilter Action:= _
    xlFilterCopy, CriteriaRange:=Range("A1:C2"), CopyToRange:=Range( _
    "A6:j600000"), Unique:=False

    Application.ScreenUpdating = True

    End Sub


    Many thanks again, and thanks for your patience and deep help , it is much appreciated

  10. #10
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: how to exclude a cell from copy and past in vba

    It's amazing that you're showing your original code again after I suggested that you prepend Range() with the name of the sheet the range belongs to (and I explained that's what caused the confusion).

    So you have two tasks:

    a) Upload the VBA code to the Forum by prepending the name of the associated sheet (your code references a sheet called 'restaurant' that doesn't exist in your entire workbook: Correct that too!),

    b) Confirm if there are one or two columns that you want to appear blank.

  11. #11
    Registered User
    Join Date
    04-28-2016
    Location
    usa
    MS-Off Ver
    2007
    Posts
    48

    Re: how to exclude a cell from copy and past in vba

    Dearest Beyond Excel, my Deep apologies, Its been a long time since I used the forum and I got confused with threads and replies, good thing that great patient teachers as yourself still exist.............

    here are the amendments:

    1- this the correct vba:

    Sub Macro76()

    Application.ScreenUpdating = False

    Sheets("SUPPLIERS").Range("A6:J600000").AdvancedFilter Action:= _
    xlFilterCopy, CriteriaRange:=Range("A1:C2"), CopyToRange:=Range( _
    "A6:J600000"), Unique:=False

    Application.ScreenUpdating = True

    End Sub




    2- I need only Column (G) to appear Blank

    I hope everything is clear and correct this time, again I deeply Apologies for my mistake
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: how to exclude a cell from copy and past in vba

    Quote Originally Posted by markswan111 View Post
    2- I need only Column (G) to appear Blank
    Then use the following variant:

    Please Login or Register  to view this content.
    PHP Code: 
    Sub Macro82()
    Dim ws1 As Worksheetws2 As WorksheetLR&
    Rem --------------------------\
    Set ws1 Sheets("suppliers")
    LR ws1.Cells(Rows.Count1).End(xlUp).Row
    Set ws2 
    Sheets("ballances")
    Rem --------------------------\
    Application.ScreenUpdating False
    ws1
    .Range("A6:J" LR).AdvancedFilter 2ws2.Range("A1:C2"), ws2.Range("A6:J6"), False
    Rem 
    --------------------------\
    LR ws2.Cells(Rows.Count1).End(xlUp).Row
    If LR 6 Then ws2.Range("G7:H" LR).ClearContents
    Application
    .ScreenUpdating True
    End Sub 

  13. #13
    Registered User
    Join Date
    04-28-2016
    Location
    usa
    MS-Off Ver
    2007
    Posts
    48

    Re: how to exclude a cell from copy and past in vba

    Dearest beyond excel,

    many thanks and much appreciation for your help, the vba you provided is functional,but it did not serve my purpose.

    this command in the VBA you provided (If LR > 6 Then ws2.Range("G7:H" & LR).ClearContents) is clearing contents in Column G, thus it is clearing the Formula I have entered in Column G as well, which defeated my purpose of the VBA.

    Simply I want to use that VBA and copy and paste the Range a6:j60000 but without pasting anything into column G in balance's sheet and no clearing as well so my formula do not get erased , so I can have my own formula in there in column G

    maybe it is another misunderstanding between us, I hope there is a simple vba that can possibly do so.

    Regards

  14. #14
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,220

    Re: how to exclude a column from copy and past in vba

    Please Login or Register  to view this content.
    PMmarkswan111, if you use VBA, try to unlearn the use of rigid, redundant ranges, as is often done with formulas. Ranges should be dynamic, that is, calculated in some way. Also, there is no need to insert formulas in column G when you can easily rebuild them with a macro.

    Artik

  15. #15
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: how to exclude a cell from copy and past in vba

    Quote Originally Posted by markswan111 View Post
    2- I need only Column (G) to appear Blank
    Quote Originally Posted by markswan111 View Post
    ... this command in the VBA you provided (If LR > 6 Then ws2.Range("G7:H" & LR).ClearContents) is clearing contents in Column G, thus it is clearing the Formula I have entered in Column G as well, which defeated my purpose of the VBA.
    Have you noticed that you first asked for one thing and then asked for the opposite, right?...
    _______________________________________________

    From the macro that I already showed you, you have two options:

    Option 1. Instead of "cleaning" column G have the macro fill that column with whatever formula you want.

    Option 2. Starting the macro will save the formula. And that formula will be reset at the end of the macro instead of clearing column G.

    Choose you please.

  16. #16
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: how to exclude a column from copy and past in vba

    And I don't want to forget to mention that in none of the three workbooks that you uploaded to the Forum can you see a formula in column G of the 'balances' sheet...

  17. #17
    Registered User
    Join Date
    04-28-2016
    Location
    usa
    MS-Off Ver
    2007
    Posts
    48

    Re: how to exclude a column from copy and past in vba

    Dear beyond excel, I got it resolved thanks to you, and your patience, you did a lot more than I expected you to do, and again many thanks, it is a great learning experience from intelligent good teachers as yourself Many thanks again.

    Mark Swan

+ 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. Copy and past row range based on value in another cell
    By mariannehislop in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-27-2021, 05:43 AM
  2. copy and past from a cell value to find box
    By Khalid Al Awadhi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-09-2017, 08:38 AM
  3. VBA code to Copy and Past values into the next available cell
    By sx200n in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-2017, 11:33 AM
  4. Copy past Row if matching cell name
    By remyte in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-27-2017, 09:37 PM
  5. Copy and Past if cell equals X for each day of the week
    By chris vice in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-22-2016, 05:44 PM
  6. [SOLVED] VBA copy and past to different cell
    By namluke in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-03-2014, 12:02 PM
  7. Copy&Past Cell Value from one Column to another using VBA
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-29-2009, 01:45 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