0

Hi the below code works however I keep getting an "Overflow" error in the date column. The Dates should stop producing at the end of the adjacent column (lastrow) however the date keeps going for some reason. Please not this is only a subset of the rest of my code.

Sub TradeDump()

Dim ws As Worksheet
Dim wsp As Worksheet
Dim wsc As Worksheet
Dim i As Integer
Dim j As Integer
Dim rng As Range
Dim rnge As Range
Dim Rnger As Range
Dim ePlaceholder As Range
Dim dater As Date
Dim lastRow As Double
Dim counter As Integer
Dim howmanytrades As Integer
Dim lasthoora As Double
Dim Clearer As Range
Dim Clearer2 As Range

lastRow = ws.Cells(Rows.Count, "E").End(xlUp).Row

lasthoora = lastRow - 1

dater = wsc.Range("MonthE")

i = 1
counter = 2
howmanytrades = wsp.Range("G6", wsp.Range("G6").End(xlDown)).Rows.Count

Do Until i = lasthoora
   For j = 1 To howmanytrades
        If (j = lasthoora) Then Exit For
        ws.Cells(counter, 4).Value = dater
        counter = counter + 1
    Next j
    i = i + input1
    dater = dater + 30
Loop


End Sub
2
  • Might not be related to the problem, but consider using Long instead of Integer since there is no downside of doing so, and it can hold a larger number. Commented Mar 3, 2020 at 20:38
  • Does this answer your question? Excel VBA: Overflow error Commented Mar 3, 2020 at 20:40

1 Answer 1

0

I'm having a difficult time understanding what you are doing in your Do Until loop. Might be better off to use a For...Next. But at the very least, I would change

Do Until i = lasthoora

to

Do Until i >= lasthoora

It would save you from somehow skipping the trigger and continuing indefinitely.

Sign up to request clarification or add additional context in comments.

1 Comment

hi @jason97conners still getting the same error. Its occurring at the counter = counter + 1 code. The code essentially completes the following. But as you can see its currently overflowing. End Date CDS Deals 1/20/2022 2000000-001 1/20/2022 2000001-001 1/20/2022 2000001-002 2/19/2022 2000000-001 2/19/2022 2000001-001 2/19/2022 2000001-002 3/21/2022 3/21/2022 3/21/2022

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.