Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Bypassing Worksheets when scanning worksheets for data

Hi have a workbook with 5 worksheets. The first one is 'Main', the Second is
'Report' and the 3-5 are 'ABC', '123', 'POG'.

I want to write VBA code that looks at all spreadsheets in the workbook
except 'Main' and 'Report' and then copy data from cell A2 and B5:B10 from
each of these worksheets (data is in the same location for each worksheet)
into the 'Report' worksheet's cell A1 through to G1 (for the sheet 'ABC'), A2
through to G2 (for the sheet '123'), A3 through to G3 (for the sheet 'POG'),
etc...

How can I do this?

Thanks.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Bypassing Worksheets when scanning worksheets for data

You can enter all three sheet names in the array (only three)
For Each sh In Sheets(Array("ABC", "123", "POG'"))

Sub test()
Dim rnum As Long
Dim sh As Worksheet
rnum = 1
For Each sh In Sheets(Array("ABC", "123", "POG"))
sh.Range("A2").Copy Sheets("Report").Cells(rnum, 1)
sh.Range("B5:B10").Copy
Sheets("Report").Cells(rnum, 2).PasteSpecial xlPasteValues, , False, True
Application.CutCopyMode = False
rnum = rnum + 1
Next
End Sub





--
Regards Ron de Bruin
http://www.rondebruin.nl


"Jig Bhakta" wrote in message ...
Hi have a workbook with 5 worksheets. The first one is 'Main', the Second is
'Report' and the 3-5 are 'ABC', '123', 'POG'.

I want to write VBA code that looks at all spreadsheets in the workbook
except 'Main' and 'Report' and then copy data from cell A2 and B5:B10 from
each of these worksheets (data is in the same location for each worksheet)
into the 'Report' worksheet's cell A1 through to G1 (for the sheet 'ABC'), A2
through to G2 (for the sheet '123'), A3 through to G3 (for the sheet 'POG'),
etc...

How can I do this?

Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Bypassing Worksheets when scanning worksheets for data

Sub AAA()
Dim v as Variant, j as Long, i as Long
Dim sh as Worksheet
v = Array("ABC","123","POG")
j = 0
for i = lbound(v) to ubound(v)
set sh = worksheets(v(i))
j = j + 1
With worksheets("Main")
.cells(j,1).Value = sh.Range("A2")
.cells(j,2).Resize(1,6).Value = _
Application.Transpose(sh.Range("B5:B10").Value)
End with
Next i
end Sub

This gets the value from those cells.

--
Regards,
Tom Ogilvy

"Jig Bhakta" wrote:

Hi have a workbook with 5 worksheets. The first one is 'Main', the Second is
'Report' and the 3-5 are 'ABC', '123', 'POG'.

I want to write VBA code that looks at all spreadsheets in the workbook
except 'Main' and 'Report' and then copy data from cell A2 and B5:B10 from
each of these worksheets (data is in the same location for each worksheet)
into the 'Report' worksheet's cell A1 through to G1 (for the sheet 'ABC'), A2
through to G2 (for the sheet '123'), A3 through to G3 (for the sheet 'POG'),
etc...

How can I do this?

Thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to consolidate all worksheets data into 1 worksheets? Janet L Excel Discussion (Misc queries) 1 April 24th 09 10:49 AM
How use info in Excel shared worksheets to create new worksheets dkc Excel Worksheet Functions 0 June 28th 07 08:36 PM
How do i assign the ActiveWorkbook.Worksheets to a worksheets object? TS Excel Worksheet Functions 2 December 27th 06 02:49 PM
Assigning Cells in worksheets to other data in other worksheets. David McRitchie Excel Discussion (Misc queries) 0 November 27th 04 06:15 PM
Need code to protect worksheets - amount of worksheets varies Sandy[_3_] Excel Programming 1 September 9th 03 02:17 AM


All times are GMT +1. The time now is 07:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"