Application-Defined Error: 1004

HimanshuK

New Member
Joined
Jun 14, 2016
Messages
23
Hi Everyone,

I have created the below code and a user defined function to-
- To specify the range of cells based on the input dates -->sdate and edate variable
-Run the user defined function searchcolumns based on input of range

Below is the code

Private Sub CommandButton2_Click()


Dim rstr, rend, sdate, edate As Long
Dim ws, rng As String


ws = Sheets("BG").range("J2").Value
sdate = Sheets("BG").range("J3").Value
edate = Sheets("BG").range("J4").Value


rstr = Application.WorksheetFunction.Match(sdate, Sheets(ws).range("$A:$A"), 0)
rend = Application.WorksheetFunction.Match(edate, Sheets(ws).range("$A:$A"), 0)


Let rng = "C" & rstr & ":" & "W" & rend


Sheets("BG").range("J5").Value = SearchColumns(Sheets(ws).range(rng), ",")


End Sub



I am getting Run time error: 1004 with rstr. I think then I also might get this at rend

Can anyone tellme what to do next so that I resolve it?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Your declaration is wrong, you have to specify the type for each variable indivdually:

Code:
Dim rstr As Long, rend As Long, sdate As Long, edate As Long
Dim ws As String, rng As String
 
Upvote 0
Greetings,

I realize that you just joined and welcome :)

Please see Here for information regarding cross-posting without advisement.

Mark
 
Upvote 0

Forum statistics

Threads
1,214,540
Messages
6,120,107
Members
448,945
Latest member
Vmanchoppy

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