I am working with a workbook that i have created. The workbook has around thirty worksheets all with the starting nave of "DIV". I have a code that will loop throught the wrok book and copy the used range and insert them into a master. However what i need is a code that will loop through the wroksheets and only copy the used range only in columns A:P and starting in row 10 (i have headers from row 1-10). I have columns beyond "P" that has working information for that worksheet and do not want to copy it over to the master.
Thank you for the help..
Hi,
Use something like
Sub CopyUsedRange Dim lUsedRows as Long, x as Long For x = 1 to Sheets.Count If Left(Sheets(x).Name,3) = "DIV" lusedRows = Sheets(x).Range("A10").CurrentRegion.Rows.Count Sheets(x).Range("A10:P" & lUsedRows).Copy Destination:= ' rest of your code here End If Next x End Sub
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
The code you gave me only seems to copy one row. I believe it could be because there is blank rows in the range. Is there a way for it to go all the way to the bottom and then com back up to the first cell with value. I cannot get rid of the blank rows, they must remain.
Thank you
Hi,
Yes, just substitute
RgdslUsedRows = Range(Sheets(x).Range("A10") , Sheets(x).Range("A" & Rows.Count).End(xlUp)).Rows.Count
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
I am getting a run time error on that code line
Hi,
Have you substituted it for the original line
and left all the other code in place?lusedRows = Sheets(x).Range("A10").CurrentRegion.Rows.Count
Rgds
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
I did change it out. here is the code i am working with
Private Sub CommandButton1_Click()
Dim DESTSH As Worksheet
Dim Last As Long
Dim lUsedRows As Long, x As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
' delete existing rows in estimate sheet
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("ESUM").Select
Rows("13:10000").Select
Selection.DELETE Shift:=x1up
On Error GoTo 0
Application.DisplayAlerts = True
Set DESTSH = ActiveWorkbook.Worksheets("ESUM")
For x = 1 To Sheets.Count
If Left(Sheets(x).Name, 3) = "DIV" Then
lUsedRows = Range(Sheets(x).Range("A10"), Sheets(x).Range("A" & Rows.Count).End(xlUp)).Rows.Count
Last = LASTROW(DESTSH)
Sheets(x).Range("A10:P" & lUsedRows).Copy Destination:=DESTSH.Cells(Last + 1, 1)
End If
Next x
ExitTheSub:
Application.Goto DESTSH.Cells(1)
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Maybe this:
lUsedRows = Range(Sheets(x).Range("A10"), Sheets(x).Range("A" & Rows.Count).End(xlUp)).Row
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
it made no difference.
Or:
lUsedRows = Sheets(x).Range("A" & Rows.Count).End(xlUp).Row
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
HI
try these codes
raviSub vexcel() Dim a As Long, x As Long, y As Long Worksheets("ESUM").Cells.ClearContents For a = 1 To Sheets.Count If Worksheets(a).Name <> "ESUM" Then x = Worksheets(a).Range("A65536").End(xlUp).Row Worksheets(a).Range("A10:P" & x).Copy y = Worksheets("ESUM").Range("B65536").End(xlUp).Row Worksheets("ESUM").Range("A" & y + 2) = Worksheets(a).Name Worksheets("ESUM").Range("B" & y + 2).PasteSpecial End If Next a MsgBox "Complete" End Sub
Ravi, resist the urge to hardcode a bottom row number like that. Each version of Excel has a different "bottom row" and hardcoding 65536 can have bad results on Excel 2007+ users.
Use the Rows.Count syntax in place of the hardcoded number so Excel always starts from the actual bottom of the sheet, regardless of version.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Hi
Thanks JB for your suggestion. I will do so hereafter.
Ravi
Hi,
I have searched and searched in almost all the forums, but i have not been able to achieve what i need. I have to create a work sheet for my manager where he will assign different task/projects to us, and the same would be a updated in a shared file kept in our common DIR thus whenever we open we can view our individual sheets view the task assigned and update accordingly.
Now, i have already created a Master sheet where task assigned gets populated on individual sheet but i am stuck at is how get the master sheet updated for column (Status) & column(update) when we update our sheets in column (F) & column (G) the same needs to be updated on master sheet ?
Formula/macro anything is it possible?
please
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks