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.
Post Details
- Posted
- 10 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/vba/comment...