I am trying to write a VBA script on Excel 2011 For Mac and having limited success.
Depending on the value in cell A1, the script needs to unhide the rows below.
If A1 = 1, it needs to unhide row B.
If A1 = 2, it needs to unhide rows B and C.
If A1 = 3, it needs to unhide rows B, C and D.
...and so on, up to a maximum A1 value of 8.
The values in A1 use data validation to be looked up from a list elsewhere on the sheet.
Thank you!
If you say B, C, D
, it seems you mean Columns , not Rows .
You can use this:
Range("B1").Resize(1, Range("A1")).EntireColumn.Hidden = False
Select Case Range("A1").Value
Case 1
Range("A2").EntireRow.hidden = false
Case 2
Range("A2,A3").EntireRow.hidden = false
'...
Case Else
MsgBox("Invalid number in cell A1")
End Select
in this case A2 would refer to row 2, A2,A3 would be 2 and 3 etc etc
EDIT:
per your comment maybe something like this would be better
Dim rng as Range
Dim val as Integer
val = Range("AE25").Value
if (val >= 1) then
set rng = Range("A26:A27").Resize(val,0)
rng.EntireRow.Hidden = false
end if
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.