Hi,
I've tried and tried to solve this but can't really wrap my head around it.
I'm relatively new to VBA and could really need som help.
I have a sheet in which a person need to fill out the name of a customer in column B.
If colum B has a value they also need to fill out colums C,D,E,H and I on the same row.
The macro needs to work between row 26 to 111.
See below for my macro which works perfectly for row 26.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = False
Application.EnableEvents = True
If Range("B26") <> "" Then
If Range("C26") = "" Then
Cancel = True
Message = Message & Range("C24") & Range("C25") & " måste fyllas i för kunden " & Range("B26") & "." & Chr$(13)
End If
If Range("D26") = "" Then
Cancel = True
Message = Message & Range("D24") & " " & Range("D25") & " måste fyllas i för kunden " & Range("B26") & "." & Chr$(13)
End If
If Range("E26") = "" Then
Cancel = True
Message = Message & Range("E25") & " måste fyllas i för kunden " & Range("B26") & "." & Chr$(13)
End If
If Range("H26") = "" Then
Cancel = True
Message = Message & Range("H24") & " " & Range("H25") & " måste fyllas i för kunden " & Range("B26") & "." & Chr$(13)
End If
If Range("I26") = "" Then
Cancel = True
Message = Message & Range("I24") & " " & Range("I25") & " måste fyllas i för kunden " & Range("B26") & "." & Chr$(13)
End If
End If
If Cancel = True Then MsgBox Message
End Sub
I can repeat this macro by adding this code after but change the range to B27 and then add another one referencing B28 but after a few of these I get an error saying "procedure is too long"
So basically I need to loop the macro in some way.
Txh,
//Stefan
Bookmarks