problem In ranges in macro

harshab6

Active Member
Joined
Oct 1, 2008
Messages
254
Hi Experts,
I have created the macro in order to consolidate sheets only having sheet name june,11 It works fine But I want the macro to select range from A4:A2000 even after giving the ranges it selects the data from A2 I have used both select and activate command but its not working its simple but I am not able to figure it out can anyone help me with this.
Sub x()
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Dim ws As Worksheet, wsOut As Worksheet, sName As String
<o:p> </o:p>
sName = "june'11"
<o:p> </o:p>
Set wsOut = Worksheets.Add(after:=Sheets(Sheets.Count))
<o:p> </o:p>
For Each ws In Worksheets
If UCase(ws.Name) Like UCase(sName) & "*" Then
ws.Range("A4:A2000", ws.Range("M" & Rows.Count).End(xlUp)).Copy _
wsOut.Range("A" & Rows.Count).End(xlUp)(2)
End If
Next ws
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
probably because there's only data down to M2 in column M.
Try:
Code:
ws.Range("A4:A2000", ws.Range("M" & Application.Max(ws.Range("M" & Rows.Count).End(xlUp).Row, 4))).copy_ 
wsOut.Range("A" & Rows.Count).End(xlUp)(2)
more steps version for explanations:
Code:
zz = ws.Range("M" & Rows.Count).End(xlUp).Row
zz = Application.Max(zz, 4)
ws.Range("A4:A2000", ws.Range("M" & zz)).copy [SIZE=3][FONT=Calibri]wsOut.Range("A" & Rows.Count).End(xlUp)(2)[/FONT][/SIZE]
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,733
Members
452,939
Latest member
WCrawford

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