Hello,
I am attempting to set a range based on dates selected. I have a "From" Calendar and a "To" Calendar and I select a "From" and "To" date then click Run and a new form will pop up and show an image of the Spreadsheet in the range I am searching for.
I had it working when I had an input box pop up and ask for me to input the range, but this is not working:
Option Explicit
Private Sub cdrTo_Click()
txtTo.Value = cdrTo.Value
End Sub
Private Sub cdrFrom_Click()
txtFrom.Value = cdrFrom.Value
End Sub
Private Sub cmdRun_Click()
Dim objTemp As Object, MyChart As Chart, rngImg As Range
Dim iRow As Long
Dim iRowX As Long
Dim FromDate As Date
Dim ToDate As Date
On Error GoTo ErrHandler
If txtFrom.Value = "" Then
MsgBox "You have not entered a 'From' date."
Exit Sub
End If
If txtTo.Value = "" Then
MsgBox "You have not entered a 'To' date."
Exit Sub
End If
FromDate = cdrFrom.Value
ToDate = cdrTo.Value
iRow = Range("A3:A10000").Find(FromDate, Range("A3"), xlValues, xlWhole, xlByColumns, xlNext).Row
iRowX = Range("A3:A10000").Find(ToDate, Range("A3"), xlValues, xlWhole, xlByColumns, xlNext).Row
ws.Activate
Selection.Copy
Set rngImg = "A" & iRow & ":I" & iRowX
rngImg.Copy
Set objTemp = ws.Shapes.AddShape(1, 1, 1, 1, 1)
objTemp.Select
ws.Paste
objTemp.Delete
With Selection
.CopyPicture 1, 2
Set MyChart = ws.ChartObjects.Add _
(1, 1, .Width, .Height).Chart
With MyChart
.Paste
.Export "Temp.jpg"
.Parent.Delete
End With
.Delete
End With
With frmView.Controls("Image1")
.Picture = LoadPicture("Temp.jpg")
.PictureSizeMode = fmPictureSizeModeZoom
End With
Kill "Temp.jpg"
frmView.Show
ErrHandler:
MsgBox ("This date is not in the system.")
End Sub
I know it is finding the correct row value, but I cannot seem to find a way to transfer the row values into the range.
Any help you can offer is really appreciated!
I am attempting to set a range based on dates selected. I have a "From" Calendar and a "To" Calendar and I select a "From" and "To" date then click Run and a new form will pop up and show an image of the Spreadsheet in the range I am searching for.
I had it working when I had an input box pop up and ask for me to input the range, but this is not working:
Option Explicit
Private Sub cdrTo_Click()
txtTo.Value = cdrTo.Value
End Sub
Private Sub cdrFrom_Click()
txtFrom.Value = cdrFrom.Value
End Sub
Private Sub cmdRun_Click()
Dim objTemp As Object, MyChart As Chart, rngImg As Range
Dim iRow As Long
Dim iRowX As Long
Dim FromDate As Date
Dim ToDate As Date
On Error GoTo ErrHandler
If txtFrom.Value = "" Then
MsgBox "You have not entered a 'From' date."
Exit Sub
End If
If txtTo.Value = "" Then
MsgBox "You have not entered a 'To' date."
Exit Sub
End If
FromDate = cdrFrom.Value
ToDate = cdrTo.Value
iRow = Range("A3:A10000").Find(FromDate, Range("A3"), xlValues, xlWhole, xlByColumns, xlNext).Row
iRowX = Range("A3:A10000").Find(ToDate, Range("A3"), xlValues, xlWhole, xlByColumns, xlNext).Row
ws.Activate
Selection.Copy
Set rngImg = "A" & iRow & ":I" & iRowX
rngImg.Copy
Set objTemp = ws.Shapes.AddShape(1, 1, 1, 1, 1)
objTemp.Select
ws.Paste
objTemp.Delete
With Selection
.CopyPicture 1, 2
Set MyChart = ws.ChartObjects.Add _
(1, 1, .Width, .Height).Chart
With MyChart
.Paste
.Export "Temp.jpg"
.Parent.Delete
End With
.Delete
End With
With frmView.Controls("Image1")
.Picture = LoadPicture("Temp.jpg")
.PictureSizeMode = fmPictureSizeModeZoom
End With
Kill "Temp.jpg"
frmView.Show
ErrHandler:
MsgBox ("This date is not in the system.")
End Sub
I know it is finding the correct row value, but I cannot seem to find a way to transfer the row values into the range.
Any help you can offer is really appreciated!