Help with If Statement Using a Lr Variable

RunTime91

Active Member
Joined
Aug 30, 2012
Messages
290
Office Version
  1. 365
Greetings all...

Code:
With WsTempHold
   Lr1 = .Cells(.Rows.Count, "G").End(xlUp).Row + 1
   .Range("G" & Lr1) = Me.CmbItemRqstdAdd.Value

Dim X As Strng, Cell as Range

For Each Cell In .Range("G2:G" & Lr1)
   If(Len(Cell.Value)>10 And .Cells(.Rows.Count, "G").End(xlUp).Row <> .Range("G" & Lr1) Then
   X = X & Cell.Value & Chr(10)

Else

   X = X & Cell.Value

End If

Next

What I'm trying do is simply add a carriage return to each cell string value except for the last one
The code doesn't error but it also doesn't work when the last string value is in Range("G" & Lr1) it doesn't move to the 'Else' statement

Help?

Thank You...
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I'm confused by this part of the conditional.
.Cells(.Rows.Count, "G").End(xlUp).Row <> .Range("G" & Lr1)

That is testing if the Cell G(LR1) contains a value that isn't equal to the number of rows in column G.
Are you sure that you want to test the contents of G[lastrow] ?
 
Upvote 0
How about
Code:
For Each cll In .Range("G2:G" & LR1)
   If Len(Cell.Value) > 10 And cll.Row <> LR1 Then
      X = X & Cell.Value & Chr(10)
   Else
      X = X & Cell.Value
   End If
Next
 
Upvote 0
Hey Mike...

Noooo... Ahhh there it is...

What I want test is if the row number of the last .Cell.Value is equal to Lr1

Where did I go wrong?
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top