VBA combine advanced filter and dynamic range

Joined
May 19, 2019
Messages
1
I have one sheet of raw data containing 12 month with few hundreds of ID for each month. The no. of rows for each month varies. Now, I want to copy the respective month data to sheet1. By changing the number of 1/2/3 (representing the month), the data for each month can auto displayed.



Month1
RankIDxxxxxxxxxx

<tbody>
</tbody>
^sheet1

xxMonthIDxxxxxxxxxx
1/1/2019
1/2/2019
1/3/2019
etc

<tbody>
</tbody>
^raw data

By changing the number(in red) in sheet1, the table below will auto display the relevant month data.

I have figured out how to copy paste the dynamic table range through VBA. But it cannot be changed auto with key in the no. of month. I have to change the month in raw data sheet manually. Below is what I have tried so far.

Sub Autofill()
Dim rawdata As Worksheet
Dim sheet1 As Worksheet


Dim rowStartRawdata As Integer
Dim rowStartsheet1 As Integer
Dim rowEndRawdata As Long


Set rawdata = ThisWorbook.Sheets("raw data")
Set sheet1 = ThisWorkbook.Sheets("sheet1")


rowStartRawdata = 2
rowStartsheet1 = 8
rowEndRawdata = rawdata.Cells(Rows.Count, "A").End(xlUp).Row


With rawdata
.Range(.Cells(rowStartRawdata, 3), .Cells(rowEndRawdata, 5)).copy (sheet1.Cells(rowStartsheet1,2))
End With
End Sub


****** id="cke_pastebin" style="position: absolute; top: 72px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">I have figured out how to copy paste the dynamic table range through VBA. But it cannot be changed auto with key in the no. of month. I have to change the month in raw data sheet manually. Below is what I have tried so far.</body>
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Use the Worksheet_Change event of Sheet1 with the target being the cell the month number is entered into to filter the Raw Data table.
Use the macro recorder while manually filtering the table to see how vba goes about it.
Alter the recorded macro to use a variable (=target.value) for the month number.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,957
Latest member
Hat4Life

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