PC Review


Reply
Thread Tools Rate Thread

create a loop so i don't have to keep retyping?

 
 
DarrenL
Guest
Posts: n/a
 
      11th Jun 2009
code is as follows, it's getting old retyping this over and over!!! can
anyone help with a loop for this? I just need to hide the row following a
cell the user types in if the cell is blank.....repeatedly.

Dim rng As Range
Set rng = Me.Range("c18")
If Not Intersect(rng, Target) Is Nothing Then
Rows(19).EntireRow.Hidden = IsEmpty(rng.Value)
End If

Dim rng2 As Range
Set rng2 = Me.Range("c19")
If Not Intersect(rng2, Target) Is Nothing Then
Rows(20).EntireRow.Hidden = IsEmpty(rng2.Value)
End If

Dim rng3 As Range
Set rng3 = Me.Range("c20")
If Not Intersect(rng3, Target) Is Nothing Then
Rows(21).EntireRow.Hidden = IsEmpty(rng3.Value)
End If

Dim rng4 As Range
Set rng4 = Me.Range("c21")
If Not Intersect(rng4, Target) Is Nothing Then
Rows(22).EntireRow.Hidden = IsEmpty(rng4.Value)
End If

 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      11th Jun 2009
I think you're looking for something like this

Option Explicit
Sub Test()

Dim rng As Range
Set rng = Me.Range("C18")

Do
If Not Intersect(rng, Target) Is Nothing Then
rng.Offset(1, 0).EntireRow.Hidden = IsEmpty(rng.Value)
End If
Set rng = rng.Offset(1, 0)
Loop While Not IsEmpty(rng)

End Sub

HTH,
Barb Reinhardt

"DarrenL" wrote:

> code is as follows, it's getting old retyping this over and over!!! can
> anyone help with a loop for this? I just need to hide the row following a
> cell the user types in if the cell is blank.....repeatedly.
>
> Dim rng As Range
> Set rng = Me.Range("c18")
> If Not Intersect(rng, Target) Is Nothing Then
> Rows(19).EntireRow.Hidden = IsEmpty(rng.Value)
> End If
>
> Dim rng2 As Range
> Set rng2 = Me.Range("c19")
> If Not Intersect(rng2, Target) Is Nothing Then
> Rows(20).EntireRow.Hidden = IsEmpty(rng2.Value)
> End If
>
> Dim rng3 As Range
> Set rng3 = Me.Range("c20")
> If Not Intersect(rng3, Target) Is Nothing Then
> Rows(21).EntireRow.Hidden = IsEmpty(rng3.Value)
> End If
>
> Dim rng4 As Range
> Set rng4 = Me.Range("c21")
> If Not Intersect(rng4, Target) Is Nothing Then
> Rows(22).EntireRow.Hidden = IsEmpty(rng4.Value)
> End If
>

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      11th Jun 2009
Try

Dim rng As Range
Set rng = Me.Range("c18:C21")
If Not Intersect(rng, Target) Is Nothing Then
Rows(Target.Row + 1).EntireRow.Hidden = IsEmpty(rng.Value)
End If


If this post helps click Yes
---------------
Jacob Skaria


"DarrenL" wrote:

> code is as follows, it's getting old retyping this over and over!!! can
> anyone help with a loop for this? I just need to hide the row following a
> cell the user types in if the cell is blank.....repeatedly.
>
> Dim rng As Range
> Set rng = Me.Range("c18")
> If Not Intersect(rng, Target) Is Nothing Then
> Rows(19).EntireRow.Hidden = IsEmpty(rng.Value)
> End If
>
> Dim rng2 As Range
> Set rng2 = Me.Range("c19")
> If Not Intersect(rng2, Target) Is Nothing Then
> Rows(20).EntireRow.Hidden = IsEmpty(rng2.Value)
> End If
>
> Dim rng3 As Range
> Set rng3 = Me.Range("c20")
> If Not Intersect(rng3, Target) Is Nothing Then
> Rows(21).EntireRow.Hidden = IsEmpty(rng3.Value)
> End If
>
> Dim rng4 As Range
> Set rng4 = Me.Range("c21")
> If Not Intersect(rng4, Target) Is Nothing Then
> Rows(22).EntireRow.Hidden = IsEmpty(rng4.Value)
> End If
>

 
Reply With Quote
 
Jennifer
Guest
Posts: n/a
 
      11th Jun 2009
On Jun 11, 1:15*pm, DarrenL <Darr...@discussions.microsoft.com> wrote:
> code is as follows, it's getting old retyping this over and over!!! *can
> anyone help with a loop for this? *I just need to hide the row following a
> cell the user types in if the cell is blank.....repeatedly.
>
> * * Dim rng As Range
> * * Set rng = Me.Range("c18")
> * * If Not Intersect(rng, Target) Is Nothing Then
> * * * Rows(19).EntireRow.Hidden = IsEmpty(rng.Value)
> * * End If
>
> * * *Dim rng2 As Range
> * * Set rng2 = Me.Range("c19")
> * * If Not Intersect(rng2, Target) Is Nothing Then
> * * * Rows(20).EntireRow.Hidden = IsEmpty(rng2.Value)
> * * End If
>
> * * *Dim rng3 As Range
> * * Set rng3 = Me.Range("c20")
> * * If Not Intersect(rng3, Target) Is Nothing Then
> * * * Rows(21).EntireRow.Hidden = IsEmpty(rng3.Value)
> * * End If
>
> * * Dim rng4 As Range
> * * Set rng4 = Me.Range("c21")
> * * If Not Intersect(rng4, Target) Is Nothing Then
> * * * Rows(22).EntireRow.Hidden = IsEmpty(rng4.Value)
> * * End If


Dim X as Integer

For X = 18 to 21

Dim rng3 As Range
Set rng3 = Me.Range("c" & X)
If Not Intersect(rng3, Target) Is Nothing Then
Rows(X).EntireRow.Hidden = IsEmpty(rng3.Value)
End If

Next X
 
Reply With Quote
 
DarrenL
Guest
Posts: n/a
 
      11th Jun 2009
Jennifer,
Thanks, yours was the only one that i could actually get to work. However,
the problem is that the row being hidden has to be dependant on whether the
row above it had anything written in column A. See my code below:
Dim rng As Range
> > Set rng = Me.Range("c18")
> > If Not Intersect(rng, Target) Is Nothing Then
> > Rows (19) .EntireRow.Hidden = IsEmpty(rng.Value)
> > End If


ANY MORE THOUGHTS?
Thanks so much BTW!
"Jennifer" wrote:

> On Jun 11, 1:15 pm, DarrenL <Darr...@discussions.microsoft.com> wrote:
> > code is as follows, it's getting old retyping this over and over!!! can
> > anyone help with a loop for this? I just need to hide the row following a
> > cell the user types in if the cell is blank.....repeatedly.
> >
> > Dim rng As Range
> > Set rng = Me.Range("c18")
> > If Not Intersect(rng, Target) Is Nothing Then
> > Rows(19).EntireRow.Hidden = IsEmpty(rng.Value)
> > End If
> >
> > Dim rng2 As Range
> > Set rng2 = Me.Range("c19")
> > If Not Intersect(rng2, Target) Is Nothing Then
> > Rows(20).EntireRow.Hidden = IsEmpty(rng2.Value)
> > End If
> >
> > Dim rng3 As Range
> > Set rng3 = Me.Range("c20")
> > If Not Intersect(rng3, Target) Is Nothing Then
> > Rows(21).EntireRow.Hidden = IsEmpty(rng3.Value)
> > End If
> >
> > Dim rng4 As Range
> > Set rng4 = Me.Range("c21")
> > If Not Intersect(rng4, Target) Is Nothing Then
> > Rows(22).EntireRow.Hidden = IsEmpty(rng4.Value)
> > End If

>
> Dim X as Integer
>
> For X = 18 to 21
>
> Dim rng3 As Range
> Set rng3 = Me.Range("c" & X)
> If Not Intersect(rng3, Target) Is Nothing Then
> Rows(X).EntireRow.Hidden = IsEmpty(rng3.Value)
> End If
>
> Next X
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
(Complex) Loop within loop to create worksheets =?Utf-8?B?a2x5c2VsbA==?= Microsoft Excel Programming 1 20th Mar 2007 12:03 AM
how can i remove retyping? =?Utf-8?B?TU9TVCBJTVBPUlRBTlQgRk9SIE1F?= Microsoft Access 1 10th Jul 2006 05:45 PM
Retyping on a form =?Utf-8?B?S3Jpc3N5?= Microsoft Access Forms 3 4th Nov 2005 04:35 PM
Highlighting & Retyping =?Utf-8?B?eW9ya2llbG92ZXIwMg==?= Microsoft Word Document Management 2 27th Jul 2005 08:19 PM
How do I create a For loop within a For loop? =?Utf-8?B?TGlua2luZyB0byBzcGVjaWZpYyBjZWxscyBpbiBw Microsoft Excel Programming 2 24th Jan 2005 08:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:28 AM.