Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Is there a way to shorten this?

Nevermind, didnt copy the whole statement. Thank

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Is there a way to shorten this?

No prob. :-

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there away to shorten Steved Excel Worksheet Functions 2 April 17th 08 08:21 PM
Can I shorten this any? Gregory Day Excel Worksheet Functions 1 April 10th 08 06:29 PM
Any way to shorten this up? Kevin M Excel Worksheet Functions 2 November 6th 06 07:50 PM
shorten formula PACable Excel Worksheet Functions 8 October 27th 05 12:39 AM
Shorten A Name rocket0612 Excel Discussion (Misc queries) 3 June 14th 05 11:37 AM


All times are GMT +1. The time now is 05:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"