for and next statements

  1. B

    Using an integer to call next values

    I have the following code to copy a select range of cells from one sheet and past it to another sheet when specific checkboxes are checked: Rng1 = ("A4:I14") Rng2 = ("A15:I26") If Sheets("Setup").Cells(nbr, 3).Value = True Then Sheets("TestPro").Range(Rng1).Copy PasteValues End If This...
  2. R

    Error Handling

    Hi, I have some code with opens a file one at a time from a list and this works fine until the file in the list cannot be found in the already specified location. My only problem is what the code does when the file cannot be found. Currently, Excel displays a error message and then gives me...
  3. N

    VBA Highlighting under multiple conditions

    Hey, I have a sheet here that auto-populates with a list of warnings/errors. they start at row 3 and keep going until the list is finished. I'm trying to find a way to highlight only errors if there is no false positive message offset 2 columns from that error. This works fine for highlighting...
  4. J

    Error-Handling for Repeat VBA Code for Multiple Values

    I think the code is fairly self-explanatory, but I'm trying to search for a number (VehNum) in a column (VehCol) and copy all of the rows with the same number in the that column to a new sheet. I'm receiving a "Run-time error 1004: Application-defined or object-defined error" in 14th line of...
  5. E

    For...Next Sheet Help!!!

    Public Sub Insert_Identifiers() Dim count As Integer For count = 1 To 2 'MY CODE Sheets(count).Columns("A:A").Select Next count End Can any one tell me what I am doing wrong that I have manually select sheet2 in order for the code to work. I really am blind sided as to what I am doing wrong.
  6. J

    Compare rows between 2 sheets - slow

    Hi, This works but can anyone think of a way to make it faster? It needs to look through over 15,000 rows. Set Sh_1 = ActiveWorkbook.Sheets("NFC Allocations") Set Sh_2 = ActiveWorkbook.Sheets("RSL") For r = 2 To Sh_1.UsedRange.Rows.Count For s = 2 To...
  7. O

    Next without for error msg & I have end if

    I am stumped...any ideas why i get the "Next without for" error message? checkstructure is the name of the function. My suspicion is the "Exit For" in the Else statement is not allowed? Dim STVal As String STVal = "ST050" Dim i As Integer Dim myanswer As Double Dim myCheckVal As Boolean...
  8. A

    Find Next within For

    Hi everyone, I have a list of production lines in one worksheet, say Production Line 1 Production Line 2 I go through the list of production lines with the help of For and a variable that takes the name of each line in turn then I go into another list and for each production line a variable...
  9. B

    Finding a value in a range in a for/next loop...

    Hello all, Apologies in advance if this is very basic and has been asked a hundred times, but I can't seem to find a solution I can adapt for what I need :( I've got a workbook with several worksheets in it. As time goes on, new sheets will be added, and some deleted. I've cobbled together...
  10. A

    VBA Code issue - Please Help!

    Hi everyone, Can anyone tell what is wrong with the following If in For? The macro would not resume the Next bit - the if works just fine but only the first row is investigated then the execution terminates without ever getting to the second row. 'First complex If - see Decision Tree tab...
  11. L

    For Loops

    Hi, I have written a very simple code to understand how the for loops work in VBA. I would like to add the letters dd in column 3 if column 2 = F2000. This is what I have: Sub dd() Dim i As Long Dim j As Long For i = 1 To i = 3 For j = 1 To j = 2 If Cells(i, 2) = F2000 Then...
  12. P

    Nested for loops in Excel

    Hey Everyone, I'm having difficulty with writing nested for loops in VBA. Could someone help me out just a little by giving me the equivalent of the following algorithm? for(i=1;i<200;i++) { for(j=1;j<1063;j++) { for(k=1;k<1063;k++) { if(table1(i,j)&&table1(i,k)!=0) {...
  13. C

    How to skip to Next in a for loop if a condition is met?

    If the cell is empty, I would like to continue on through the loop without performing any other tests... For x = 1 To lastrow Data = Str(F1.Cells(x, 1)) ActiveSheet.Cells(x, 1).Select If IsEmpty(ActiveCell.Value) Then ???? If Data <> "0" Then Ary1(x, 1) = Data: g = g + 1 Next
  14. C

    How to end For loop If condition is met.

    Seems like there should be a way to goto Next if the empty cell condition is met but I can't find it. For x = 1 To lastrow Data = Str(F1.Cells(x, 1)) ActiveSheet.Cells(x, 1).Select If IsEmpty(ActiveCell.Value) Then ???? If Data <> "0" Then Ary1(x, 1) = Data: g = g + 1 Next
  15. W

    ThisWorkbook Function breaks within "For" statement

    Hi, I keep getting a break referring to "ThisWorkbook". Can anyone help? For i = 2 To lastline Columns("AL").Replace _ What:=ThisWorkbook.Sheets("Metric").Cells(i, 1), Replacement:=ThisWorkbooks.Sheets("Metric").Cells(i, 2), _ LookAt:=xlWhole, MatchCase:=False Next
  16. W

    How do I make the following "For" VBA faster?

    Hi, I'm working with the following VBA to remove text/blank but its very slow when working with larger data files. Is there a way to make it faster? For i = Lastline To 1 Step -1 If Not IsNumeric(Cells(i, 1).Value) Then Rows(i).Delete If Cells(i, 1) = "" Then Rows(i).Delete...
  17. D

    Clearing ListBox Selection

    I'm using the code below to hide or unhide and activate worksheets in my workbook. I would like to add code to deselect the original selection in the listbox, however when I try to add code to several places I receive a Run-Time 9 error, subscript out of range. Private Sub lbSheets_Change()...
  18. M

    for next loop calculating percentages grades

    Students assignement1 assignement2.. blank clmn total(%) a 12 9 5 b 15 6 4 max pt on *** 20 10...
  19. B

    VBA Code - Consolidate 2 macros with For Each Statements

    Hello... Somewhat experience with basic and self taught. Need some help.. I have 2 separate macros and wanted to combine them. The issue is the two differetn For Each statements. Both steps are on the same worksheet and I am trying to consolidate the steps. I know it is very simple code...
  20. R

    VBA problem: For … next loop with 2 matrices

    Dear experts, I have tried to create a VBA code that would pick up information form matrix 2 and store that in matrix 1 (the actual report). The first variable in matrix 1 is a date (column A, the second one is a unique fleet number (column B). What I want is the stops for each fleet number...

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