Looping trouble

reeliq

New Member
Joined
Jul 22, 2011
Messages
6
I'm trying to nest two loops inside one another with If/Then also.

I need to check a list of data for certain names. When that name is found I need to copy certain data on the same row and paste it elsewhere. I have this set up without any problems but I also need to loop through about 80 cells per line (of data that matches the previous criteria) to find anything that has a value of "N".

I have the first part and loop done but I can't get the section loop to work propertly. Below is my current code for this.

Any help would be much appreciated.

Sub QA_Audits_Move()
Dim xReps As Integer
Dim MaxRow As Integer
Dim AC As Integer
Dim Last As Integer
Dim Insert As Integer
Dim QA As Integer
Dim EBQT As Integer
Dim Crit As Integer
Dim Lastcolumn As Integer

CurRpt = ActiveWorkbook.Name
ShtName = ActiveSheet.Name
Cells(2, 10).Select
RptDateN = Cells(2, 5)
'
' Eric's Team
Cells(1, 1).Select
Selection.End(xlDown).Select
MaxRow = ActiveCell.Row
Cells(1, 3).Select
Selection.End(xlToRight).Select
Lastcolumn = ActiveCell.Column
For xReps = 1 To MaxRow
Cells(xReps, 2).Select
AC = ActiveCell.Row
If (Activecell = "My name") Then
If Cells(AC, 1) = "Manager" Then
Range(Cells(AC, 2), Cells(AC, 6)).Copy
Workbooks("Quality Tracker").Sheets("Eric's Team").Activate
Cells(Rows.Count, 1).End(xlUp)(2).Select
Selection.PasteSpecial xlPasteValues
End If

Workbooks(Format(RptDateN, "MM-DD") & "Master".Activate

For Crit = 6 To Lastcolumn
Cells(AC, 6).Select
If (ActiveCell = 1) Then
Range(Cells(AC, 2), Cells(AC, 6)).Copy
Cells(Rows.Count, 1).End(xlUp)(2).Select
Selection.PasteSpecial xlPasteValues
End If
Next Crit

End If

Next xreps
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
It is only selecting one cell and looping through that one cell.

It goes to cell(AC,6) and goes through this cell 5 or 6 times then ends the loop and moves on.

It does this instead of looping through all 80 cells I need to search.

I thought I set the 2nd loop up the same as the first but it isn't working the same as the 1st.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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