简体   繁体   中英

Copy rows based on cell value and paste on a new sheet

Check This

在此处输入图片说明

I need a help. I want to copy whole cell from A sheet name "Components" only if value in Column C is > 0 to a new Sheet name "Load list"

Can someone please give me the macro code for this?

on your new sheet you can add this condition the cell or range of cells:

=IF(Components!C5>0,Components!A5)

where C5 has thevalue to compare, and A5 has the value copy if the condition happens.

Right in my swing!

The formula given by @sweetkaos will work fine, in case you want to replicate the data as it is with blanks where data is not found.

I will imagine a slightly more complicated situation. I am assuming you want just one line in the next format as is shown in your image.

Also conveniently assuming the following: a. both sheets have fixed start points for the lists b. 2 column lists - to be copied and pasted, with second column having value c. Continuous, without break source list d. basic knowledge of vba, so you can restructure the code

Here is the code. Do try to understand it line by line. Happy Excelling!

Sub populateLoadList()    
'declaring range type variables
Dim rngStartFirstList As Range, rngStartLoadList As Range

'setting values to the range variables
'you must change the names of the sheets and A1 to the correct starts of your two lists

Set rngStartFirstList = Worksheets("Name_of_your_fist_sheet").Range("A1")

Set rngStartLoadList = Worksheets("Name_of_your_second_sheet").Range("A1")


Do While rngStartFirstList.Value <> ""
  If rngStartFirstList.Offset(1, 0).Value < 0 Then

     Range(rngStartFirstList, rngStartFirstList.Offset(0, 1)).Copy      

     rngStartLoadList.PasteSpecial xlPasteValues

     Application.CutCopyMode = False

     Set rngStartLoadList = rngStartLoadList.Offset(1, 0)

   End If

   Set rngStartFirstList = rngStartFirstList.Offset(1, 0)

Loop
End Sub

基本上我想要的是......如果 C 上的值 >0 我想要整个第 10 列复制到那个新工作表......不仅仅是那个单元格

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM