For Loop Fail

livvi_77

New Member
Joined
Aug 8, 2011
Messages
6
So this for loop was previously working but with new data set has decided not to work. Please help!

For x = 1 To x = n
Qx = Worksheets("Working").Range("Qx")
If I * x = I * (x + 1) Then
Qx = " "
End If
Next x

I want it to look in column Q and if the data is the same as the data in the cell below for it to make the cell on that row in column I to be blank. The data in column Q is alpha numeric. Any help would be much appreciated.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Qx = Worksheets("Working").Range("Qx")

well for starters Qx cannot = itself before its set... maybe under range put
Range("Q" & x) to get the next row in the line

and is I defined higher up in this code? needs to know what I is
 
Upvote 0
I tried adding that but hasn't done anything.

Sub MacroTaxi()
Sheets("Working").Visible = True
Sheets("Working 2").Visible = True

Sheets("Working").Select
Rows("1:62160").Select
Range("A62160").Activate
Rows("1:62160").EntireRow.AutoFit
Columns("A:R").Select
Application.CutCopyMode = True

Sheets("TAXI DATA").Select
Columns("D:U").Select
Application.CutCopyMode = True
Selection.Copy
Sheets("Working").Select
Range("A1").Select
ActiveSheet.Paste

'Define variables

Dim n As Integer
Dim x As Integer

'Count number of entries in spreadsheet
n = Worksheets("Working").Range("I:I").Cells.SpecialCells(xlCellTypeConstants).Count

'Start For Loop
For x = 1 To x = n
Qx = Worksheets("Working").Range("Q" & x)
If I * x = I * (x + 1) Then
Qx = "Blank"
End If
Next x

'Sheets("Working").Select
'Columns("A:R").Select
'Application.CutCopyMode = True
'Selection.Copy
'Sheets("Working 2").Select
'Range("A1").Select
'ActiveSheet.Paste

'Range("A1:R2060").Select
'Selection.Sort Key1:=Range("Q1"), Order1:=xlDescending, Header:= _
'xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
'DataOption1:=xlSortNormal

'Sheets("Working 2").Select
'Columns("F:F").Select
'Application.CutCopyMode = True
'Selection.Copy
'Sheets("Top 20 Taxis by Volume").Select
'Range("B1").Select
'ActiveSheet.Paste
'Sheets("Working 2").Select
'Columns("H:I").Select
'Application.CutCopyMode = True
'Selection.Copy
'Sheets("Top 20 Taxis by Volume").Select
'Range("C1").Select
'ActiveSheet.Paste
'Sheets("Working 2").Select
'Columns("M:R").Select
'Application.CutCopyMode = True
'Selection.Copy
'Sheets("Top 20 Taxis by Volume").Select
'Range("E1").Select
'ActiveSheet.Paste


'Sheets("Working").Select
'ActiveWindow.SelectedSheets.Visible = False
'Sheets("Working 2").Select
'ActiveWindow.SelectedSheets.Visible = False

End Sub

Heres my coide in full have made the bottom half into comments to try and find out where its going wrong. Im trying to get unique data because I have a count column which counts the number of journeys each person has taken but then if someone has made four journeys ther will be four fours so am trying to make it so theres just one.
 
Upvote 0
have you tried hitting F8 and going through each line and value one by one? i find it helps alot. any chance for a sample worksheet?
 
Upvote 0
Yep I've tried going through it but it just highlights every line. Im afraid I can't give you a sample worksheet because of issues of confidentitality but in column I is an alphanumeric code thats unique for each person and column Q is simply a count column that just counts the number of entries per person.
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,553
Members
449,170
Latest member
Gkiller

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top