Crosswords1 min ago
Visual Basic Macro Code
5 Answers
I'm probably being lazy but was hoping some expert could tell me how to fix the code Excel created. I've tried this a few times in the past for no success, and it seems simple enough that it should be easily editable.
Range("A2").Select
Selection.Cut
Range("F1").Select
ActiveSheet.Paste
Rows("2:2").Select
Selection.Delete Shift:=xlUp
Range("A2").Select
The above is a mess. It is defining specific cells when any normal default should be to note movements relative to start and encode them.
What I was trying to achieve was:
Start at whatever cell you are in. (Column A)
Drop down a row and cut the data in the cell there, which ought not be there.
Move back up a row and move across to 5 cells (Column F)
Paste the data there, where it should have been, instead.
Highlight the row below (from where data has just been removed).
Delete it as it is no longer of use.
The highlighted cell should now be in column A of the next line of data, i.e. one row below where we started, so that the macro can be run again on the next as yet unfixed data.
Can anyone clarify what it is I need to change in the code to stop these absolute references and turn them into relative ones ? (I'm using Office 2003 so I can't just tell it to act sensible when recording, as far as I know.)
Cheers.
Range("A2").Select
Selection.Cut
Range("F1").Select
ActiveSheet.Paste
Rows("2:2").Select
Selection.Delete Shift:=xlUp
Range("A2").Select
The above is a mess. It is defining specific cells when any normal default should be to note movements relative to start and encode them.
What I was trying to achieve was:
Start at whatever cell you are in. (Column A)
Drop down a row and cut the data in the cell there, which ought not be there.
Move back up a row and move across to 5 cells (Column F)
Paste the data there, where it should have been, instead.
Highlight the row below (from where data has just been removed).
Delete it as it is no longer of use.
The highlighted cell should now be in column A of the next line of data, i.e. one row below where we started, so that the macro can be run again on the next as yet unfixed data.
Can anyone clarify what it is I need to change in the code to stop these absolute references and turn them into relative ones ? (I'm using Office 2003 so I can't just tell it to act sensible when recording, as far as I know.)
Cheers.
Answers
Use activecell. offset( 1, 0). activate to select the row below where you are and then ActiveCell. EntireRow. Delete (I think)
14:55 Thu 15th Jun 2017
I felt we did and I'd assigned an icon button to it, but one day I opened Excel, the button icon had gone, and the macro had stopped working. It's the way life is these days. As I have grown older the world has become less logical, less rational. Inexplicable things happen regularly. Ho hum ...
I'll give your suggestions a try. Thanks.
I'll give your suggestions a try. Thanks.
Router fell off the Net for ages so wasn't able to look much up.
Sub SORT_DATA()
'
' Macro recorded 15/06/2017 by Old_Geezer
'
ActiveCell.Offset(1, 0).Select
Selection.Cut
ActiveCell.Offset(-1, 5).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Activate
ActiveCell.EntireRow.Delete
ActiveCell.Offset(0, -5).Select
End Sub
Yay ! Thanks. Now I have to try not to lose it again.
Sub SORT_DATA()
'
' Macro recorded 15/06/2017 by Old_Geezer
'
ActiveCell.Offset(1, 0).Select
Selection.Cut
ActiveCell.Offset(-1, 5).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Activate
ActiveCell.EntireRow.Delete
ActiveCell.Offset(0, -5).Select
End Sub
Yay ! Thanks. Now I have to try not to lose it again.
Related Questions
Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.