ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel Macro Basic Help (https://www.excelbanter.com/excel-programming/298663-excel-macro-basic-help.html)

Adam[_9_]

Excel Macro Basic Help
 
I have never written Excel macros or written in Visual
Basic before. I am trying to write a macro that will
organize my spreadsheet into a certain order. In order
to do that, I need to be able to search for a row that
has a 0 in the first column cut that row to the beginning
of my file. Here is what I have, but it isn't working.

For n = 2 To FinalRow
If (Range("A" & n).Value) = 0 Then
Rows("n:n").Select
Selection.Cut
Rows("2:2").Select
Selection.Insert Shift:=xlDown
End If
Next n

Thank you

Bob Phillips[_6_]

Excel Macro Basic Help
 
Adam,

Just adapting your code

For n = 2 To FinalRow
If (Range("A" & n).Value) = 0 Then
Rows(n & ":" & n).Cut
Rows("2:2").Insert Shift:=xlDown
End If
Next n

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Adam" wrote in message
...
I have never written Excel macros or written in Visual
Basic before. I am trying to write a macro that will
organize my spreadsheet into a certain order. In order
to do that, I need to be able to search for a row that
has a 0 in the first column cut that row to the beginning
of my file. Here is what I have, but it isn't working.

For n = 2 To FinalRow
If (Range("A" & n).Value) = 0 Then
Rows("n:n").Select
Selection.Cut
Rows("2:2").Select
Selection.Insert Shift:=xlDown
End If
Next n

Thank you




Tom Ogilvy

Excel Macro Basic Help
 
Sorting your data doesn't do what you want?

--
Regards,
Tom Ogilvy

"Adam" wrote in message
...
I have never written Excel macros or written in Visual
Basic before. I am trying to write a macro that will
organize my spreadsheet into a certain order. In order
to do that, I need to be able to search for a row that
has a 0 in the first column cut that row to the beginning
of my file. Here is what I have, but it isn't working.

For n = 2 To FinalRow
If (Range("A" & n).Value) = 0 Then
Rows("n:n").Select
Selection.Cut
Rows("2:2").Select
Selection.Insert Shift:=xlDown
End If
Next n

Thank you





All times are GMT +1. The time now is 07:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com