Forum Discussion
Macro functions
- May 17, 2021
You have to loop through the cells:
Sub MoveCells() Dim r As Long Application.ScreenUpdating = False For r = 2 To 100 If Worksheets("PICK").Range("A" & r).Value = "YES" Then Worksheets("PICK").Range("C" & r).Resize(1, 3).Cut _ Destination:=Worksheets("PRINT").Range("A" & r) End If Next r Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
Thanks for your help. I am a macro and VB beginner (I used to program in COBOL)
I have got the script running but only for row 1. I have many rows with a YES that I want to copy over, how do I 'loop' the script to do row 2:100 say.
I got this far:
Sub MoveCells()
If Worksheets("PICK").Range("A1").Value = "YES" Then
Worksheets("PICK").Range("C1:E1").Copy Destination:=Worksheets("PRINT").Range("A1:E1")
Application.CutCopyMode = False
End If
I did try - If Worksheets("PICK").Range("A1:A100").Value = "YES" Then
but I get an error
Cheers, Pete
You have to loop through the cells:
Sub MoveCells()
Dim r As Long
Application.ScreenUpdating = False
For r = 2 To 100
If Worksheets("PICK").Range("A" & r).Value = "YES" Then
Worksheets("PICK").Range("C" & r).Resize(1, 3).Cut _
Destination:=Worksheets("PRINT").Range("A" & r)
End If
Next r
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub- FennsterMay 20, 2021Copper ContributorHi Hans,
After a lot of fiddling, I finally got it to work, fantastic and many thanks.
I Didn't realise that the positioning of the syntax is as important as the function.
What I would like to do now is be able to delete or mark, from my original 'list of data' those items (rows) that have been selected with a YES.
Basically within the workbook I have 3 sheets.
MAIN - Contains the full list of data.
PICK - That I copy all data from MAIN into but then set up my Y selection.
The user puts a YES against the required items for that day.
Then I run your super SUB that copies the YES items into a third PRINT Sheet
Thereby, creating my Print List for the day.
Your next challenge is:
What I would like to do is 'mark' on the original list MAIN that the row has previously been
selected within the PICK sheet. I think I would need to give each row in the MAIN sheet a Seq No so that the lines in the PICK Sheet can refer back to the rows in the MAIN Sheet and perhaps 'shade' the row or mark the row somehow, to show that it has previously been selected??
Would that be possible,
For now, I will get the user to shade the rows in the MAIN sheet, using the printed list as a guide.
Thanks for all your help so far, Cheers, Pete
PS: My brother lives in Holland, a place called Drunen
PPS: Am I allowed to give you my email address?- HansVogelaarMay 20, 2021MVP
Hi Pete,
I live about 30 miles north-east of Drunen. And yes, you can give me your email address if you like.
You will indeed have to add some kind of unique identifier to the items, for example a sequence number.
Which column would you like to use for that?
- FennsterMay 21, 2021Copper ContributorHi Hans,
It's going to be easier to communicate vie email.
My address is: pete.fenn@live.com
I look forward to hearing from you,
Cheers, Pete