Coming soon - Get a detailed view of why an account is flagged as spam!
view details
0
Getting a Run-time error with my range, any ideas why?
Post Body

Solved I ended up fixing it just by creating a string variable StartCell and feeding it the actual cell I wanted to start at from my userform (i.e. "C3") and it's working now. Thanks for the help!

Once again, /r/VBA, I come to you for help! I'm trying to write a code to fill a range with dates given the starting cell, starting date, end date, and number of times to repeat each date. Unfortunately, I'm getting Run-time error 1004: Method 'Range' of object '_Worksheet' failed.

The relevant parts are:

Dim ws As Worksheet
Dim i As Integer
Dim rowStart As Integer, colStart As Integer
Dim startCell As Range

Set ws = ActiveSheet
rowStart = txtRow.Value
colStart = txtColumn.Value


Dim dateStart As Date, dateEnd As Date, days As Integer
dateStart = DateValue(txtStart.Value)
dateEnd = DateValue(txtEnd.Value)
days = DateDiff("d", dateStart, dateEnd)

Dim rep As Integer, rangeLength As Integer
rep = txtRep.Value
rangeLength = rep * days

Dim fillRange As Range
Set startCell = ws.Cells(rowStart, colStart)
Set fillRange = ws.Range(startCell).Resize(rangeLength)

It's the last line that it's getting hung up on, and I can't figure anything out from googling the error. Thanks for any help! Also, I'm assuming it's bad form to Dim everything all over the place rather than at the start, but I've just been winging it as I code and am planning to clean it up once it all works.

Author
Account Strength
100%
Account Age
16 years
Verified Email
Yes
Verified Flair
No
Total Karma
24,663
Link Karma
4,393
Comment Karma
20,260
Profile updated: 4 days ago
Posts updated: 10 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
10 years ago