ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If row 2 (https://www.excelbanter.com/excel-programming/407321-if-row-2-a.html)

Judy Ward

If row 2
 
The code I have (below) does what I want it to do--searches for the cell that
has more than 255 characters, then cuts and pastes that row to the top of the
spreadsheet (row 2). But it throws an error when it finds the cell in row 2
and tries to cut and insert itself.

I want to put in a condition to test if row 2 (because no action is needed),
but I can't figure out how to do it. Can anyone help?

Private Sub FindMemoRow()
Dim Lcell As Range
For Each Lcell In Range("L:L")
' Looking for a cell with more than 255 characters
If Len(Lcell) 255 Then
Range(Lcell.Address).Select
Selection.EntireRow.Select
Selection.Cut
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Exit Sub
End If
Next Lcell
End Sub

Thank you,
Judy

Mike H

If row 2
 
Try this

Private Sub FindMemoRow()
Dim Lcell As Range
For Each Lcell In Range("L:L")
If Lcell.Row < (2) Then

If Len(Lcell) 255 Then
Range(Lcell.Address).Select
Selection.EntireRow.Select
Selection.Cut
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Exit Sub
End If
End If
Next Lcell
End Sub


Mike

"Judy Ward" wrote:

The code I have (below) does what I want it to do--searches for the cell that
has more than 255 characters, then cuts and pastes that row to the top of the
spreadsheet (row 2). But it throws an error when it finds the cell in row 2
and tries to cut and insert itself.

I want to put in a condition to test if row 2 (because no action is needed),
but I can't figure out how to do it. Can anyone help?

Private Sub FindMemoRow()
Dim Lcell As Range
For Each Lcell In Range("L:L")
' Looking for a cell with more than 255 characters
If Len(Lcell) 255 Then
Range(Lcell.Address).Select
Selection.EntireRow.Select
Selection.Cut
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Exit Sub
End If
Next Lcell
End Sub

Thank you,
Judy


PCLIVE

If row 2
 
Do you really need to look at each of the 65,536 cells in column L? Why not
give it a specific range in which I'm assuming you'd want to start at L3?

Private Sub FindMemoRow()
Dim Lcell As Range
For Each Lcell In Range("L3:L" & Range("L65536").End(xlUp).Row)
' Looking for a cell with more than 255 characters
If Len(Lcell) 255 Then
Range(Lcell.Address).EntireRow.Cut
Range("A2").EntireRow.Select
Selection.Insert Shift:=xlDown
Exit Sub
End If
Next Lcell
End Sub


HTH,
Paul

--

"Judy Ward" wrote in message
...
The code I have (below) does what I want it to do--searches for the cell
that
has more than 255 characters, then cuts and pastes that row to the top of
the
spreadsheet (row 2). But it throws an error when it finds the cell in row
2
and tries to cut and insert itself.

I want to put in a condition to test if row 2 (because no action is
needed),
but I can't figure out how to do it. Can anyone help?

Private Sub FindMemoRow()
Dim Lcell As Range
For Each Lcell In Range("L:L")
' Looking for a cell with more than 255 characters
If Len(Lcell) 255 Then
Range(Lcell.Address).Select
Selection.EntireRow.Select
Selection.Cut
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Exit Sub
End If
Next Lcell
End Sub

Thank you,
Judy




Judy Ward

If row 2
 
Thank you both, Mike H and PCLIVE, for responding. These are both very
useful suggestions. My problem is solved.

Thank you again,
Judy

"PCLIVE" wrote:

Do you really need to look at each of the 65,536 cells in column L? Why not
give it a specific range in which I'm assuming you'd want to start at L3?

Private Sub FindMemoRow()
Dim Lcell As Range
For Each Lcell In Range("L3:L" & Range("L65536").End(xlUp).Row)
' Looking for a cell with more than 255 characters
If Len(Lcell) 255 Then
Range(Lcell.Address).EntireRow.Cut
Range("A2").EntireRow.Select
Selection.Insert Shift:=xlDown
Exit Sub
End If
Next Lcell
End Sub


HTH,
Paul

--

"Judy Ward" wrote in message
...
The code I have (below) does what I want it to do--searches for the cell
that
has more than 255 characters, then cuts and pastes that row to the top of
the
spreadsheet (row 2). But it throws an error when it finds the cell in row
2
and tries to cut and insert itself.

I want to put in a condition to test if row 2 (because no action is
needed),
but I can't figure out how to do it. Can anyone help?

Private Sub FindMemoRow()
Dim Lcell As Range
For Each Lcell In Range("L:L")
' Looking for a cell with more than 255 characters
If Len(Lcell) 255 Then
Range(Lcell.Address).Select
Selection.EntireRow.Select
Selection.Cut
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Exit Sub
End If
Next Lcell
End Sub

Thank you,
Judy






All times are GMT +1. The time now is 06:11 AM.

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