If column value = 0 then copy cell in column A,B and C to another sheet below existing columns

radeon187

New Member
Joined
Mar 25, 2020
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Good Day!

I would like to see if its possible to do the following via VBA:
  1. Define a column header (header = result) in sheet1 to look at values
  2. If value in result header = 0 copy contents from row for header "Make", "Model" and "ID"
  3. Paste contents from above to sheet2 in rows with column headers "Make","Model" and "ID" below existing data in sheet2
Example sheet1:
RVTools_export_dfw5infvcn001_2020-03-24_15.09.19 (1).xlsx
ABCD
1MakeModelResultID
2FordF15019255
3HondaAccord09265
4ChevyBolt18652
5LexusIS01927
6FordBronco01025
7FordF25013952
8HondaPilot11257
9ChevyBlazer12217
10LexusES06364
Sheet1


Example sheet2:
RVTools_export_dfw5infvcn001_2020-03-24_15.09.19 (1).xlsx
ABC
1MakeModelID
2FordF1505467
3HondaAccord5487
4ChevyBolt2125
5LexusIS5688
6FordBronco6214
7FordF2503347
8HondaPilot4496
9ChevyBlazer5568
10LexusES2148
Sheet2


Example of desired result:
RVTools_export_dfw5infvcn001_2020-03-24_15.09.19 (1).xlsx
ABC
1MakeModelID
2FordF1505467
3HondaAccord5487
4ChevyBolt2125
5LexusIS5688
6FordBronco6214
7FordF2503347
8HondaPilot4496
9ChevyBlazer5568
10LexusES2148
11HondaAccord9265
12LexusIS1927
13FordBronco1025
14LexusES6364
Sheet2



Keep in mind, I would like to designate everything by column header name. Thanks in advance!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hey, if I'm understanding this correctly you basically want to find the rows on sheet 1 that have a 0 in the header column and copy them to the bottom of your list on sheet 2?

If so, it's a simple case of applying a filter to sheet 1 on column 'header' where the filter value is 0. Then copying the result of the filter to a new area, remove the header and paste the result to the bottom of your list on sheet 2
 
Upvote 0
Hey, if I'm understanding this correctly you basically want to find the rows on sheet 1 that have a 0 in the header column and copy them to the bottom of your list on sheet 2?

If so, it's a simple case of applying a filter to sheet 1 on column 'header' where the filter value is 0. Then copying the result of the filter to a new area, remove the header and paste the result to the bottom of your list on sheet 2
Thats a great idea @denzo36! Is there vba code that I could use to accomplish this? Also, for the copy and paste from sheet1 to sheet2, I would need to specify the coumn headers where the data needs to be placed in sheet2 since the columns will vary.
 
Upvote 0
If your pictures are a true reference of your actual sheets, try this.
Change referenced where required.
VBA Code:
Sub Maybe()
Application.ScreenUpdating = False
With Sheets("Sheet1").Range("A1:D" & Range("A" & Rows.Count).End(xlUp).Row)
    .AutoFilter 3, 0
    .Columns(3).EntireColumn.Hidden = True
    .Offset(1).SpecialCells(12).Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1)
End With
With ActiveSheet
    .AutoFilterMode = False
    .Columns(3).EntireColumn.Hidden = False
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
If the Headers are not in the same order, maybe this will do.
Change references if and where required.
VBA Code:
Sub Maybe_2()
Dim mArr, i As Long, sh1 As Worksheet, sh2 As Worksheet
mArr = Array("Make", "Model", "ID")
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")
Application.ScreenUpdating = False
    With sh1.Range("A1:D" & Range("A" & Rows.Count).End(xlUp).Row)
        .AutoFilter 3, 0
            For i = LBound(mArr) To UBound(mArr)
                Cells(1, sh1.Rows(1).Find(mArr(i), , , 1).Column).Offset(1).Resize(sh1.UsedRange.Rows.Count).SpecialCells(12).Copy _
                sh2.Cells(Rows.Count, sh2.Rows(1).Find(mArr(i), , , 1).Column).End(xlUp).Offset(1)
            Next i
    End With
ActiveSheet.AutoFilterMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0
VBA Code:
With sh1.Range("A1:D" & Range("A" & Rows.Count).End(xlUp).Row)
should be
VBA Code:
With sh1.Range("A1:D" & sh1.Range("A" & Rows.Count).End(xlUp).Row)
I have to check yet but I don't think it needs to be
VBA Code:
With sh1.Range("A1:D" & sh1.Range("A" & sh1.Rows.Count).End(xlUp).Row)
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top