Set Range using Row Values in VBA

DaveLoos

New Member
Joined
Sep 22, 2011
Messages
4
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!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Welcome to the board..

This line
Set rngImg = "A" & iRow & ":I" & iRowX
Should be
Set rngImg = Range("A" & iRow & ":I" & iRowX)


If that's not it, post the relevant inputbox code that WORKED
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top