for loop

  1. P

    Can someone tell me what's wrong with my code? For loop

    Hi, can someone have a look at the code below. It's long, but repetitive. Each IF statement works but only for the first IF comparable, and the ELSE. All of the ElseIF's don't seem to be working and I can't figure out why. Trying to spruce up the holiday tracker for my workforce. Column "AS"...
  2. H

    Exit Sub when For Condition is met

    Hi I want my code to exit as soon as the condition of the if statement within the for loop are met and the message box appears (shown in yellow below). When exit sub is added, it exits after the messagebox but the rest of my code does not run when the conditions are not met, and if I remove...
  3. Johnny Thunder

    VBA Help - If Filtered Range Return Nothing Then

    Hello all, I am having some issues with a statement in my current code and all sources online aren't really answering my question directly. I have a fairly long script that loops thru a range to get a filter criteria value and then apply the filter to a range on a seperate sheet. This code...
  4. Johnny Thunder

    VBA Help - Loop thru an array of Sheets in Workbook and extract first row to a Log Sheet

    Hi everyone! I am stuck on a task that I am not sure how to accomplish but it is pretty straightforward. My workbook has several sheets that I can put into an array that I want to extract only the first row of data E4:V4 and paste these values into Sheets("Daily Log") starting in the same range...
  5. M

    VBA: Find and Group All Occurrences of Value, Run Sub, Move to Next Group

    Hi, I need some help getting started on a code. I have a range ("B4:B") of variables that are related by the first four characters (the year). Currently an input box will appear asking which year to run the code in, and the default value is based on the left four characters of the active cell...
  6. M

    VBA: If Any Cell in a Range is Yellow Then Do Not Change Color.

    Hi, I have different ranges of cells where once a cell goes over a limit then that cell changes yellow. Once one cell changes yellow in the range I don't want the cells after to change yellow. The ColorIndex of every other cell is 24 if that's helpful. For example, in a range of F4:F7 if the...
  7. M

    VBA: Going to the next cell

    I have a range starting at B4 with term codes grouped together year and I'm trying to add the values that start with the same 4 digit year code. So 2019 should be 28,000; 2020 should be 28,500; and 2021 should be 6 (test sample). The idea is the user selects a cell and VBA will add that year...
  8. C

    Reference a radio button in an Array of Arrays with index in a For Loop

    I am trying to run some macros based on whether or not a radio button is selected. I am using a For Loop to do this, but cannot figure out how to reference the button based on where its name is indexed in an array of arrays which contain references to reports, buttons, and sheet names. Here is...
  9. R

    Hide Rows without a value

    Hello, I am trying to write a code that: Looks at cells in column A from rows 9:100 -If a cell does not have an integer then that cells entire row is to be hidden. This is what I have so far. Thank you. Private Sub CommandButton7_Click() '''''''''''''''''''''' Question Rollup Dim x As...
  10. S

    Loop through multiple rows per iteration with Excel VBA

    How can I convert my Excel VBA code, which currently loops by each row, to loop through 10,000 sets, with each set containing 20 rows? I understand that the Step function might work, but I can't figure out how to amend my code to enable this. Basically, I would like to "paste" an array of 20...
  11. D

    Outlook VBA to list the text strings of all folders and subfolders i.e., beyond two levels

    Hi Folks, The code below is listing the Outlook path for all my Outlook Folders but only two levels deep. e.g., \\\Inbox\01) doug's jobs\completed jobs I've tried to nest a third For loop into the code to pull out the next level of folder e.g...
  12. N

    Runtime 1004 error with For Loop

    The code below is throwing me a runtime 1004 error when I try to run the macro: Denoted with "'THIS IS WHERE THE ERROR OCCURS" I suspect this is because I am using checkboxes in the "Deliverables" worksheet to start the For, and writing content to the "ReviewContent" worksheet after the If...
  13. D

    How do I change the selection in a For loop?

    I'm trying to put a string together, compiling the words in A1:C8, by column. The output for the first column output is A10, the output for the second column is B10 etc. and I want the selection to change each time too so that it only includes column A in the A10 output, column B in the B10...
  14. D

    How do I change the output destination in a For loop

    I'm currently trying to put a string of cells together in a and complete it across several columns but I can't figure out how to change the destination for the output each time Sub test() Dim x x = 7 For x = 7 To 595 Dim rng As Range Dim i As String For Each rng In Selection i = i & rng Next...
  15. I

    Copy columns based on header and array

    Hello, I have data in Sheet1 that I'd like to copy into Sheet2 based on the header. I'd like to create some kind of text array that I can update in the code to include new columns if they become relevant. I'd like the relevant headers array to be something like sWords = {"Date", "Qty"...
  16. V

    Functionality of UBound in For loop

    What is the functionality of UBound in for loop for the below code. x = wsPlan.Range("A1").CurrentRegion.Value Set Plan = CreateObject("Scripting.Dictionary") For i = 3 To UBound(x, 1) For j = 2 To UBound(x, 2) Plan.Item(x(1, j) & x(2, j) & x(i, 1)) = x(i, j) Next j Next i
  17. G

    Repeated cells in same column VBA

    I am struggling to create a simple loop that will allow me to repeat a cell value down a column for a number of my choosing. I want to turn this: A1 A2 A3 Into this ("2", for example): A1 A1 A2 A2 A3 A3 Anything helps! Thank you.
  18. Mackeral

    Problem changing For Loop Maximum inside the loop

    Consider the following code: Last = 10 For I = 1 To Last Last = Last + 1 Next I At the end of the code you find I = 11 and Last = 21. The implication of this is that once you set the Maximum for the loop, you can't change it. So you have to use a Do While loop explicitly...
  19. A

    For Loop with data formatted as Time (hh:mm:ss)

    Hi everyone, I'm trying to create a for loop that iterates through each row in Column M. The data in this column is formatted as a time (Hours:Minutes:Seconds), I would like to flag any data (by highlighting the cell in red) greater than or equal to 7 minutes (00:07:00). The code I have now...
  20. B

    for loop using variable

    I am trying to use a variable to determine how many times to go thru a loop. The code that I am trying to get to work is shown below. If I use 'For S1 = 1 to 2", I go inside my loop 2 times. If I use 'For S1 = 1 to NumofTimes', I do not get inside my loop. The Msgboxes show a value of 1 and a...

Some videos you may like

This Week's Hot Topics