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?
 

Some videos you may like

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

jkpieterse

Well-known Member
Joined
Dec 3, 2007
Messages
1,080
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
 

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,154
Greetings,

I realize that you just joined and welcome :)

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

Mark
 

Watch MrExcel Video

Forum statistics

Threads
1,123,341
Messages
5,601,052
Members
414,425
Latest member
eerenyuan

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
Top