Macro to control two workbook
Hello,
I have a file with 3 worksheets. I assigned a macro to a combo box on sheet1. The macro only controls sheet2. How can I modify this macro so it works for both sheet2 and sheet3? Sheet2 and sheet3 are identical. Sub RwHide() Dim RwCnt As Integer For RwCnt = 8 To 138 If Range("N" & RwCnt) = 0 Then Range("N" & RwCnt).EntireRow.Hidden = True End If Next For RwCnt = 8 To 138 If Range("N" & RwCnt) < 0 Then Range("N" & RwCnt).EntireRow.Hidden = False End If Next End Sub Thanks a lot, LLee |
Macro to control two workbook
Here is one way... use a structure like this (substitute your own code where
indicated making sure to follow the rule laid out in the comments).... Sub Test() Dim WScount As Long Dim ROWcount As Long Dim WS(1 To 2) As Worksheet Set WS(1) = Worksheets("Sheet2") Set WS(2) = Worksheets("Sheet3") For WScount = 1 To 2 For ROWcount = 8 To 138 ' ' Put your code here, but put WS(WScount). in ' front of all cell references... and note the dot at ' the end of the WS(WScount). For example... ' WS(WScount).Range("A1").Value = "Hello" Next Next End Sub Rick "LLee2" wrote in message ... Hello, I have a file with 3 worksheets. I assigned a macro to a combo box on sheet1. The macro only controls sheet2. How can I modify this macro so it works for both sheet2 and sheet3? Sheet2 and sheet3 are identical. Sub RwHide() Dim RwCnt As Integer For RwCnt = 8 To 138 If Range("N" & RwCnt) = 0 Then Range("N" & RwCnt).EntireRow.Hidden = True End If Next For RwCnt = 8 To 138 If Range("N" & RwCnt) < 0 Then Range("N" & RwCnt).EntireRow.Hidden = False End If Next End Sub Thanks a lot, LLee |
All times are GMT +1. The time now is 01:37 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com