Hi,
I'm not too good at vba but have ot start using it more now to get the spreadsheet do what I need.
I need the spreadsheet to go to cell D3 if cell C3 say MFL and to C4 if cell C3 says Humanities : my code only do 1 of those :(
then I need the rows 71:91 to be hidden if cell c3 says anything else than English, Maths or Science
and then I need to be able to write long comments in merged cells in row: 13,15,17,27,29, etc and if text is long I need it to be wrapped automatically. (for now it works if I name 1 merged cell Expand_Row )
i tried to find some codes on net so they're not mine but they work if only 1 of them is there but if i want them all to work they dont.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim C3 As Range, F3 As Range, J3 As Range, D3 As Range
Set C3 = Range("C3")
Set D3 = Range("D3")
Set F3 = Range("F3")
Set J3 = Range("J3")
Dim MergeWidth As Single
Dim cM As Range
Dim AutoFitRng As Range
Dim CWidth As Double
Dim NewRowHt As Double
Dim str01 As String
str01 = "Expand_Row"
If Not Intersect(Target, Range(str01)) Is Nothing Then
Application.ScreenUpdating = False
On Error Resume Next
Set AutoFitRng = Range(Range(str01).MergeArea.Address)
With AutoFitRng
.MergeCells = False
CWidth = .Cells(1).ColumnWidth
MergeWidth = 0
For Each cM In AutoFitRng
cM.WrapText = True
MergeWidth = cM.ColumnWidth + MergeWidth
Next
'small adjustment to temporary width
MergeWidth = MergeWidth + AutoFitRng.Cells.Count * 0.66
.Cells(1).ColumnWidth = MergeWidth
.EntireRow.AutoFit
NewRowHt = .RowHeight
.Cells(1).ColumnWidth = CWidth
.MergeCells = True
.RowHeight = NewRowHt
End With
Application.ScreenUpdating = True
End If
If Intersect(Target, C3) Is Nothing Then Exit Sub
Application.EnableEvents = False
D3 = ""
F3 = ""
J3 = ""
Application.EnableEvents = True
If Worksheets("CLASS_ANALYSIS").Range("C3").Value = "Humanities" Then _
MsgBox ("Please select appropriate TA subject in cell C4")
Range("C4").Select
If Worksheets("CLASS_ANALYSIS").Range("C3").Value <> "Humanities" Then Range("C4") = ""
If Worksheets("CLASS_ANALYSIS").Range("C3").Value = "MFL" Then _
MsgBox ("For subject analysis please select appropriate subject in cell D3, leave D3 BLANK for Teacher or class analysis")
Range("D3").Select
If Worksheets("CLASS_ANALYSIS").Range("C3").Value <> "MFL" Then Range("D3") = ""
If Target.Address = "$C$3" And UCase(Target.Value <> ("English")) Then
Rows("71:91").Hidden = True
Else
Rows("71:91").Hidden = False
End If
If Target.Address = "$C$3" And UCase(Target.Value <> ("Maths")) Then
Rows("71:91").Hidden = True
Else
Rows("71:91").Hidden = False
End If
If Target.Address = "$C$3" And UCase(Target.Value <> ("Science")) Then
Rows("71:91").Hidden = True
Else
Rows("71:91").Hidden = False
End If
End Sub