Results 1 to 5 of 5

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

Threaded View

bullgogi Need help with VBA code that... 02-16-2023, 06:02 PM
beyond Excel Re: Need help with VBA code... 02-16-2023, 06:55 PM
bullgogi Re: Need help with VBA code... 02-17-2023, 12:17 PM
Marc L Re: Need help with VBA code... 02-17-2023, 12:34 PM
torachan Re: Need help with VBA code... 02-18-2023, 07:47 AM
  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

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