![]() |
Is there a way to shorten this?
I have to go up to 20 on my If statement here and was wondering if ther
was a way to shorten this in VBA. Example: Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Range("C6").Value = 0 Then Range("M6:AF6").Value = "-" End If If Range("C7").Value = 0 Then Range("M7:AF7").Value = "-" End If If Range("C8").Value = 0 Then Range("M8:AF8").Value = "-" End If If Range("C9").Value = 0 Then Range("M9:AF9").Value = "-" End If If Range("C10").Value = 0 Then Range("M10:AF10").Value = "-" End If If Range("C11").Value = 0 Then Range("M11:AF11").Value = "-" End If If Range("C12").Value = 0 Then Range("M12:AF12").Value = "-" End If If Range("C13").Value = 0 Then Range("M13:AF13").Value = "-" End If If Range("C14").Value = 0 Then Range("M14:AF14").Value = "-" End If If Range("C15").Value = 0 Then Range("M15:AF15").Value = "-" End If If Range("C16").Value = 0 Then Range("M16:AF16").Value = "-" End If If Range("C17").Value = 0 Then Range("M17:AF17").Value = "-" End If If Range("C18").Value = 0 Then Range("M18:AF18").Value = "-" End If End Sub Hopefully there is, otherwise I am going to be busy. -TyeJae -- Message posted from http://www.ExcelForum.com |
Is there a way to shorten this?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)for x = 6 T
18 If Cells(x, 3).Value = 0 Then Range(.Cells(x, 13), .Cells(x, 32)).Value = "-" End If End Sub I didn't test this, but it works in theory. - Piku -- Message posted from http://www.ExcelForum.com |
Is there a way to shorten this?
I could not get that to work, I copied and pasted exactly what you pu
in, am I supposed to substitute anything? -TyeJae -- Message posted from http://www.ExcelForum.com |
Is there a way to shorten this?
|
Is there a way to shorten this?
|
All times are GMT +1. The time now is 06:44 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com