Forum Discussion
Need Help Please!!
- Aug 30, 2022
Sub DNO() Dim i As Long Dim k As Long Dim l As Long l = Range("A" & Rows.Count).End(xlUp).Row k = 2 Worksheets("DNO").Range("A2:AX1048576").Clear For i = 2 To l Select Case Cells(i, 51).Value Case Is = "DNO" Range(Cells(i, 1), Cells(i, 50)).Copy Destination:=Worksheets("DNO").Cells(k, 1) k = k + 1 End Select Next i End SubMaybe with this code. In the attached file you can click the button in cell BA2 to run the code. In column AY you can enter "DNO" to copy the row to the designated sheet "DNO". I've entered random numbers in columns A to AX for this example.
If there is a warning when you open the file you have to enable the content in order to run the macro. You would have to click the button "enable content" ("Inhalt aktivieren" in german) in this case. Then the button in cell BA2 should work.
I've tried to make an example according to your requirement. In the main sheet there are 50 columns and 200 rows of random data. You can add as many rows as required. Assume that the data in row 10 is "DNO" data. You can enter "DNO" in cell AY10 and click the button in cell BA2. The macro then clears all the data in sheet "DNO" and copies the data from row 10 of the main sheet to the "DNO" sheet. You don't have to change / adapt the code for this. Of course you can copy as many rows as you want at the same time.
Perfect and makes sense, I think. I do have a few more questions though. Again, thank you for your time.
1. How do I copy it into my existing sheet?
2. Where do I copy it into my existing sheet?
3. I enabled the warning the first time I opened the workbook, but once I closed it and reopened it, it no longer gives me the warning. Either time with the warning and without the warning, the button still does not work.
- Steph_VAug 30, 2022Copper Contributor
This is a screenshot of me copying and pasting it into the macro screen. When I run it, it doesn't work. Is there something else that I need to do?
- OliverScheurichAug 30, 2022Gold Contributor
Besides the missing "Option explicit" i can't tell why it doesn't work.
Does the code return an error message if you run it (with F5)? If there isn't an error message then the code runs until the end. Do you run the macro when the main sheet is selected and did you enter "DNO" in any cells in column AY? If so the respective rows should be copied to the "DNO" sheet.
If this still doesn't work maybe you want to attach your file without sensitive data.
- Steph_VAug 31, 2022Copper ContributorGood morning,
I sent you the file via private message. Again, thank you for your help.
Steph
OliverScheurich