PC Review


Reply
Thread Tools Rate Thread

Complicated code

 
 
Miree
Guest
Posts: n/a
 
      3rd Apr 2009
I have the following code which works beautifully, I now need to modify or
write a new code to do the next step.

At the moment the code deletes the row if combobox5 does not appear in a
cell between AN and BF what I now need to do is If combobox5 does appear in
a cell I need to check that the cell 38 along (BZ to CR) has a number which
is between textbox1 and textbox2 if not delete the row

Dim rng As Range
Dim i As Long
Dim delrow As Boolean

Set rng = ActiveSheet.Range(Cells(1, "AN"), Cells(Rows.Count, "BF").End(xlUp))
rng.Select

With rng

For i = .Rows.Count To 1 Step -1
delrow = True

For j = 1 To .Columns.Count
If .Cells(i, j) = UserForm7.ComboBox5.Value Then
delrow = False
End If
Next j

If delrow = True Then .Cells(i, 1).EntireRow.Delete
Next i
End With

Any help much appreciated
 
Reply With Quote
 
 
 
 
joel
Guest
Posts: n/a
 
      3rd Apr 2009
I think you are look at the data in Column DK. I re-wrote the code so it is
easier to see which coluns you are referening to. You had one error in your
code where you weren't checking the activesheet

Cells(Rows.Count, "BF") - missing the period.
Cells(1, "AN") - missing period.

this error probably wouldn't of been a problem in this code but can cause
problems when you aren't working with the activeworksheet.

Sub test()

Dim delrow As Boolean

With ActiveSheet
LastRow = .Cells(Rows.Count, "BF").End(xlUp).Row
FirstColumn = .Range("AN1").Column
Lastcolumn = .Range("BF1").Column

For RowCount = LastRow To 1 Step -1
For ColCount = FirstColumn To Lastcolumn


delrow = True

If .Cells(RowCount, ColCount) = UserForm7.ComboBox5.Value Then
delrow = False
End If
Next ColCount

If delrow = True Then
DataValue = .Range("DK" & RowCount).Value
If Val(UserForm7.Textbox1.Value) >= DataValue And _
Val(UserForm7.Textbox2.Value) >= DataValue Then

.Rows(RowCount).Delete
End If
End If
Next RowCount

End With


End Sub


"Miree" wrote:

> I have the following code which works beautifully, I now need to modify or
> write a new code to do the next step.
>
> At the moment the code deletes the row if combobox5 does not appear in a
> cell between AN and BF what I now need to do is If combobox5 does appear in
> a cell I need to check that the cell 38 along (BZ to CR) has a number which
> is between textbox1 and textbox2 if not delete the row
>
> Dim rng As Range
> Dim i As Long
> Dim delrow As Boolean
>
> Set rng = ActiveSheet.Range(Cells(1, "AN"), Cells(Rows.Count, "BF").End(xlUp))
> rng.Select
>
> With rng
>
> For i = .Rows.Count To 1 Step -1
> delrow = True
>
> For j = 1 To .Columns.Count
> If .Cells(i, j) = UserForm7.ComboBox5.Value Then
> delrow = False
> End If
> Next j
>
> If delrow = True Then .Cells(i, 1).EntireRow.Delete
> Next i
> End With
>
> Any help much appreciated

 
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
Help with a very complicated For each Next code Ayo Microsoft Excel Programming 5 25th Aug 2009 06:34 PM
Very complicated report to go with a very complicated query....HEL ReportTrouble Microsoft Access Reports 1 14th Apr 2009 02:02 PM
Complicated Lookup Code dkk Microsoft Excel Programming 3 12th Mar 2009 06:01 PM
Help needed with Complicated code (For me !!) =?Utf-8?B?TGVz?= Microsoft Excel Programming 8 9th Jul 2007 02:28 PM
Complicated Code Bob Microsoft Excel Discussion 3 21st Apr 2004 11:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:19 PM.