ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If sh.Name < Sheet1 Then (https://www.excelbanter.com/excel-programming/410591-if-sh-name-sheet1-then.html)

ryguy7272

If sh.Name < Sheet1 Then
 
I am trying to get the below macro to perform a certain operation on a series
of worksheets in my workbook, but I don't want anything done to Sheet1. For
some reason, the code only performs the operation on Sheet1. This is the
opposite of what I want. Can someone please help out?

Sub Math()
Dim LastRow As Long
Dim c As Variant
Dim sh As Worksheet

For Each sh In Worksheets

If (sh.Name) < "Sheet1" Then
Rows("1:1").Select
Selection.Font.Bold = True

LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For Each c In Range("F2:F" & LastRow)
If c.Value < "" Then
c.Offset(, 19).Value = "=RC[-17]*RC[-2]"
End If
Next c

End If
Next sh

End Sub


Regards,
Ryan---

--
RyGuy

Gary''s Student

If sh.Name < Sheet1 Then
 
Sub Math()
Dim LastRow As Long
Dim c As Variant
Dim sh As Worksheet

For Each sh In Worksheets

If (sh.Name) < "Sheet1" Then
sh.Activate
Rows("1:1").Select
Selection.Font.Bold = True

LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For Each c In Range("F2:F" & LastRow)
If c.Value < "" Then
c.Offset(, 19).Value = "=RC[-17]*RC[-2]"
End If
Next c

End If
Next sh

End Sub

I make the same error myself....over & over.
--
Gary''s Student - gsnu200784


"ryguy7272" wrote:

I am trying to get the below macro to perform a certain operation on a series
of worksheets in my workbook, but I don't want anything done to Sheet1. For
some reason, the code only performs the operation on Sheet1. This is the
opposite of what I want. Can someone please help out?

Sub Math()
Dim LastRow As Long
Dim c As Variant
Dim sh As Worksheet

For Each sh In Worksheets

If (sh.Name) < "Sheet1" Then
Rows("1:1").Select
Selection.Font.Bold = True

LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For Each c In Range("F2:F" & LastRow)
If c.Value < "" Then
c.Offset(, 19).Value = "=RC[-17]*RC[-2]"
End If
Next c

End If
Next sh

End Sub


Regards,
Ryan---

--
RyGuy


JLGWhiz

If sh.Name < Sheet1 Then
 
You just need to tell it where it is. See modified code below.

Sub Math()
Dim LastRow As Long
Dim c As Variant
Dim sh As Worksheet

For Each sh In Worksheets

If (sh.Name) < "Sheet1" Then
Rows("1:1").Select
Selection.Font.Bold = True

LastRow = sh.Cells(Rows.Count, "F").End(xlUp).Row
For Each c In sh.Range("F2:F" & LastRow)
If c.Value < "" Then
c.Offset(, 19).Value = "=RC[-17]*RC[-2]"
End If
Next c

End If
Next sh

End Sub





"ryguy7272" wrote:

I am trying to get the below macro to perform a certain operation on a series
of worksheets in my workbook, but I don't want anything done to Sheet1. For
some reason, the code only performs the operation on Sheet1. This is the
opposite of what I want. Can someone please help out?

Sub Math()
Dim LastRow As Long
Dim c As Variant
Dim sh As Worksheet

For Each sh In Worksheets

If (sh.Name) < "Sheet1" Then
Rows("1:1").Select
Selection.Font.Bold = True

LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For Each c In Range("F2:F" & LastRow)
If c.Value < "" Then
c.Offset(, 19).Value = "=RC[-17]*RC[-2]"
End If
Next c

End If
Next sh

End Sub


Regards,
Ryan---

--
RyGuy


ryguy7272

If sh.Name < Sheet1 Then
 
Thanks GS and JLG. Now it makes sense.
Logic, logic, logic...

--
RyGuy


"JLGWhiz" wrote:

You just need to tell it where it is. See modified code below.

Sub Math()
Dim LastRow As Long
Dim c As Variant
Dim sh As Worksheet

For Each sh In Worksheets

If (sh.Name) < "Sheet1" Then
Rows("1:1").Select
Selection.Font.Bold = True

LastRow = sh.Cells(Rows.Count, "F").End(xlUp).Row
For Each c In sh.Range("F2:F" & LastRow)
If c.Value < "" Then
c.Offset(, 19).Value = "=RC[-17]*RC[-2]"
End If
Next c

End If
Next sh

End Sub





"ryguy7272" wrote:

I am trying to get the below macro to perform a certain operation on a series
of worksheets in my workbook, but I don't want anything done to Sheet1. For
some reason, the code only performs the operation on Sheet1. This is the
opposite of what I want. Can someone please help out?

Sub Math()
Dim LastRow As Long
Dim c As Variant
Dim sh As Worksheet

For Each sh In Worksheets

If (sh.Name) < "Sheet1" Then
Rows("1:1").Select
Selection.Font.Bold = True

LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For Each c In Range("F2:F" & LastRow)
If c.Value < "" Then
c.Offset(, 19).Value = "=RC[-17]*RC[-2]"
End If
Next c

End If
Next sh

End Sub


Regards,
Ryan---

--
RyGuy



All times are GMT +1. The time now is 04:42 PM.

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