VBA Userform: Need help completing coding to run a report please.

TitusandNero

New Member
Joined
Mar 17, 2016
Messages
26
Hello (operating on Excel 2007)
Hope someone can help a newbie here. I've set up a userform(named Reports) to run a report from an Excel database(named Data) which will then populate an excel spreadsheet(named By Representative) in the same workbook. On the userform(Reports) I have 3 search parameters in text boxes: Name, date1 and date2. By entering a name and date range and clicking 'run report' I'd like it to open the 'By Representative' spreadsheet and populate it.
The Names on the 'Reports' userform are in a dropdown combobox (named cbRep) and will find its match in column O or 15 in the 'Data' database
The date1 and date2 will find their match in column M or 13 in the 'Data' database. Here's my problem - I'm a newbie and I'm learning as I go. I need your help to complete my coding so that it:
A) Opens the By Representative spreadsheet after the click
B) Matches the value in column O in (Data) with the value in the combobox (cbReP) - can't seem to find the right code
C) Searches between two dates

I'd really appreciate any assistance: Here is my coding so far (which I copied from a youtube video). It is incomplete and obviously not working.

Private Sub CommandButton1_Click()
Dim sdsheet As Worksheet, ersheet As Worksheet
Set sdsheet = ThisWorkbook.sheets ("Data")
set ersheet = ThisWorkbook.Sheets ("By Representative")

If sdsheet.cells(Rows.Count, 1).End(xlUp).row = 1 Then
sdLR = 2
Else
sdLR = sdsheet.Cells(Rows.Count, 1).End(xlUp).Row
End If

y = 2 'starting row

For x = 2 To sdLR
If sdsheet.Cells(y, 1) = "Reports.cbRep" Then **There is an error here. It doesn't like "Reports.cbRep", I've tried different variations but can't seem to get it right**
ersheet.cells (y, 1) = sdsheet.cells (x, 15)
ersheet.Cells (y, 2) = sdsheet.Cells (x, 1)
ersheet.Cells (y, 3) = sdsheet.Cells (x, 10)
etc, etc..

y = y +1
End If
Next x

End Sub

Thanks you
icon7.png
 
Unfortunately that's not working still getting the same error. I don't really know what's left to do here except maybe do a bit more research and try and find a whole new code. The original Userform and database is all running super, does everything I want it to do. It's just this last bit of producing reports I can't get my head around and as I don't 'speak' code it's hard to spot where I'm going wrong. I appreciate your time and patience trying to help me.
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,215,465
Messages
6,124,977
Members
449,200
Latest member
Jamil ahmed

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