Creating Ranges based on column data

sethos

New Member
Joined
Feb 25, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I'm newer to Excel Macros and I have a lengthy manual data manipulation I'm trying to automate as much as I can. I get data in an excel sheet with many different columns and almost 10k rows and it needs parsed out to about 7 different sheets within the workbook based on the starting cell value in one column. I posted example data below. Basically I want to create a range variable, say Test_Range, and add the rows where the value in column D start with "H" so that I can cut and paste to another workbook. I'm lost as far as appending the variable. I figured I'd be using a For loop to iterate through the table (Like For Each cell In [D:D]), and then an If cell.value Like "H*" Then, but I don't understand how to add the range("A2:H2") to the variable while within the If statement but using variables. This is my thought process thus far and my current block.

Sub Parsed_Data()

Dim Test_Range as Range
For Each cell In [D:D]
-If cell.value Like "H*" Then
--Dim Row_Num As Integer
--Row_Num = cell.Row
--Dim Found_Range As Range
--Set Found_Range = ("A + Row_Num:H + Row_Num")
--Test_Range = Union(Test_Range, Found_Range)
--Else
--Endif
-Endif
Next cell

End Sub

I'm getting errors on the Line --Set Found_Range = ("A + Row_Num:H + Row_Num") for type mismatch.

1645818523057.png


I hope I'm making sense.
 
2 sheets, MySheet1 and MySheet2, with in MySheet1 a table named TBL_1 (see below)
VBA Code:
Sub Filter_Copy()
     Dim LO
     Set LO = Sheets("MySheet1").ListObjects("TBL_1")           'your table
     With LO.Range                                              'range = headers & databody of your table
          .AutoFilter                                           'reset autofilter
          .AutoFilter 3, "<=.5"                                 'filter on 3rd column for values less or equal to .5
          LO.DataBodyRange.Copy Sheets("MySheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)     'copy filtered values in the databody to another sheet
          .AutoFilter
     End With
End Sub
Map2
ABCDE
1abcde
20,3320,4410,7860,9390,227
30,2900,9900,3630,4600,517
40,3990,1710,6590,3760,990
50,0740,6530,7010,2310,085
60,8350,4370,4130,3300,036
70,6220,0310,1460,8260,300
80,5960,5790,8870,7440,474
90,7430,1310,6010,8780,694
100,7830,6220,8400,1450,635
110,6080,6240,2810,6010,838
120,0560,1500,2030,2840,506
130,3420,5250,1570,3910,194
140,2100,5930,7040,1090,349
150,2900,4180,1270,6240,389
160,8820,1180,5330,1360,566
170,9310,4000,6920,2370,507
180,9660,8100,3100,2770,226
190,0830,0410,8550,8050,920
200,0660,8240,7450,0110,723
210,8190,6940,0300,7910,439
220,3330,4660,0430,9670,261
230,7490,5230,4720,7540,795
MySheet1
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,214,987
Messages
6,122,618
Members
449,092
Latest member
amyap

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