+ Reply to Thread
Results 1 to 5 of 5

Need help with VBA code that uses checkbox "true" value to copy & paste data to new sheet

  1. #1
    Registered User
    Join Date
    02-16-2023
    Location
    Illinois
    MS-Off Ver
    Microsoft 365
    Posts
    2

    Need help with VBA code that uses checkbox "true" value to copy & paste data to new sheet

    Hi experts! I am new to VBA and am working on a workbook that has several sheets with different types of inventory and one main summary sheet.

    I am trying to use checkboxes, that if checked as "True", will copy the corresponding row of data and paste into the summary sheet starting on a specific row. Each inventory sheet has several rows of data and I'd like users to be able to check multiple boxes that they need on each sheet and this inventory data to be copied to the summary sheet.

    I found this code below that is working for the most part except it skips over some lines of data that are marked as "true". It also adds an unnecessary extra row between the lines once it copies the data over to the new sheet. What can I change so that all of the data marked "true" can be copied over and eliminate the extra rows?

    Code I found is from a Youtube video. I'd post the link but my account is too new to allow me to post the link.


    Sub CopyRowBasedOnCellValue()
    Dim xRg As Range
    Dim xCell As Range
    Dim A As Long
    Dim B As Long
    Dim C As Long
    A = Worksheets("Exterior Items").UsedRange.Rows.Count
    B = Worksheets("Customer Sheet").UsedRange.Rows.Count
    If B = 1 Then
    If Application.WorksheetFunction.CountA(Worksheets("Customer Sheet").UsedRange) = 0 Then B = 0
    End If
    Set xRg = Worksheets("Exterior Items").Range("B1:B" & A)
    On Error Resume Next
    Application.ScreenUpdating = False
    For B = 1 To xRg.Count
    If CStr(xRg(B).Value) = "True" Then
    xRg(B).EntireRow.Copy Destination:=Worksheets("Customer Sheet").Range("A" & B + 9)
    B = B + 1
    End If
    Next
    Application.ScreenUpdating = True

    End Sub

    EDIT: Added an attachment of example data set/format that I have so far.

    VBA_True_CopyPaste_Example.xlsm
    Last edited by bullgogi; 02-17-2023 at 12:16 PM. Reason: Had to add example sheet to my original post

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

    Re: Need help with VBA code that uses checkbox "true" value to copy & paste data to new sh

    Hello bullgogi.

    What you can change is the way you present the topic.

    Upload a workbook to the Forum where we can clearly see:

    - How are you going to indicate what data you intend to copy.
    - And one or two examples of finished copies.
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  3. #3
    Registered User
    Join Date
    02-16-2023
    Location
    Illinois
    MS-Off Ver
    Microsoft 365
    Posts
    2

    Re: Need help with VBA code that uses checkbox "true" value to copy & paste data to new sh

    Hi beyond Excel! Thank you for the clarification on what I should post for help. I added an excel sheet attachment to my original post that has sample data and basic format of what I have so far. Hope I did this one correct, new to this forum. Thanks again!

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Need help with VBA code that uses checkbox "true" value to copy & paste data to new sh


    Hi,

    just filter column B on TRUE then copy at once the data like any Excel user can do manually with just two operations
    so avoiding such gas factory VBA code, no need to loop except if you need a slower way than the easy user above …

  5. #5
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Need help with VBA code that uses checkbox "true" value to copy & paste data to new sh

    Alternative, get rid of the tedium of placing all those checkboxes and just place 'X' in appropriate row.
    Attached Files Attached Files
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

+ 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: 05-24-2021, 11:24 AM
  2. Replies: 1
    Last Post: 05-24-2021, 11:24 AM
  3. many actions in one macro: copy sheet "G" and paste "g_koond" no empty rows and add ID
    By reinsermat in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-05-2020, 04:28 AM
  4. [SOLVED] Copy Data from "Source" Sheet to "Target" Sheet (Code need help thanks)
    By mankit87 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 07-17-2019, 11:45 PM
  5. [SOLVED] UserForm CheckBox to output "Yes" instead of "True"
    By DomSza in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-07-2015, 10:30 AM
  6. Write a code that looks for "True" in a certain column and copy paste to a new sheet
    By rangerman50ho in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-18-2014, 03:39 PM
  7. Remove "TRUE" "FALSE" words from a linked checkbox
    By MDCK in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-15-2008, 03:26 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