0

Here's the process I have in mind:

  1. Count all cells containing data in column A (I'm thinking "xlUp"?) and set that number as a variable.
  2. Select first 400 cells in Column A (starting at A2), and fill them color Yellow.
  3. Copy that data (data is pasted to another prog ((Let's call the shortcut key "!*Z")).
  4. Subtract 400 from the total cell count variable.
  5. Select second 400 cells in Column A (starting at A402)
  6. Fill them color Yellow
  7. Copy that data (!*Z).
  8. Subtract 400 from updated cell count variable.
  9. Repeat until the last cell of data is copied and color filled.

Any help would be great.
I feel like I've been going in circles on this for too long. It's time to ask the experts. Thank you!

Dominique
  • 16,450
  • 15
  • 56
  • 112
  • 1
    Welcome to SO, please attempt it and then ask a question when you encounter any problem that you can't resolve (and also show your code attempt). – Raymond Wu Oct 25 '21 at 06:24
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 25 '21 at 06:25
  • Running in circles means that, for a long time, you are doing something. Can you show us what that is (or at least a part of it)? – Dominique Oct 25 '21 at 08:02
  • Sorry to be so general, but I deal with a lot of proprietary information. I know how to select non-colored cells, fill them, and send to my other prog. I can even get a total count of items in the column. The main thing that I just cannot wrap my head around is setting that total number as a variable, subtracting 400 from it every pass, and selecting whatever remains below 400 as the last pass. I have not been able to find examples. If anybody can point me in the right direction, that'd be great. I WANT to do this myself. I am not asking for free programming :) – Leeroy-a-Jenkins Oct 25 '21 at 14:50
  • [This answer](https://stackoverflow.com/a/69691513) to *How to slice an array in batches in VBA*, posted only yesterday, illustrates an interesting way of dealing with this. – VBasic2008 Oct 25 '21 at 14:57
  • This is EXACTLY what i needed. Thanks! – Leeroy-a-Jenkins Oct 25 '21 at 15:12

1 Answers1

0

Batch Range

  • Here is my quick (short) vision of the suggested post applied to your case. Please, do share if you find an improvement.
Option Explicit

Sub BatchRange()
    
    Const sfRow As Long = 2
    Const sCol As String = "A"
    Const Batch As Long = 400
 
    ' Create a reference to the First Cell.
    Dim sfCell As Range: Set sfCell = Sheet1.Cells(sfRow, sCol)
    ' Calculate the last row.
    Dim slRow As Long
    slRow = Sheet1.Cells(Sheet1.Rows.Count, sCol).End(xlUp).Row
    
    Dim srCount As Long: srCount = slRow - sfRow + 1
    Dim bCount As Long: bCount = Int(srCount / Batch) + 1
    
    Dim srg As Range
    Dim b As Long
    Dim r As Long
    
    For b = 1 To bCount
        
        If b = bCount Then
            r = srCount Mod Batch
        Else
            r = Batch
        End If
        
        If r > 0 Then
            ' Create a reference to the current Column Range.
            Set srg = sfCell.Resize(r)
            
            
            ' Do your stuff
            ' e.g.:
            Debug.Print sfCell.Address(0, 0), srg.Address(0, 0)
            ' or:
            srg.Interior.Color = vbYellow
            
            
            ' Create a reference to the next First Cell.
            Set sfCell = sfCell.Offset(r)
        End If
    
    Next b
    
End Sub
VBasic2008
  • 44,888
  • 5
  • 17
  • 28
  • VBasic2008 Reading through this, I think I get it. I was trying to go a different direction with what little knowledge I have. I'll give this a shot at work later this week and report back. Thanks for the help! I certainly wasn't expecting this. – Leeroy-a-Jenkins Oct 25 '21 at 19:29