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
Bookmarks