LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 1
Default Copying record value from column in multiple sheets into single sh

Hi,

I have some employee Records in sheets "Nov07","Dec07" and "Jan08".
the first two columns(A and B) are employee number and name in each sheet,
and column C is their overtime.

I want to create a consolidated sheet "YTD" so that I can see all their YTD
overtime in one sheet and do some analysis.

Hence the new sheet will have first two columns A and B same as above howver
column C, D and E will be the overtime from each sheet. It would have been a
simple copy paste if the number of employee had been static, but it changes
every months as new employee joins in or some leaves. Hence the macro needs
to validate employee number before copying the value from source sheet to
destination sheet

I have tried my best to create a Macro to do the same as below:

Dim Rno As Integer
Dim Svalue, OValue As String

Sub CopyCol()
For Each Tmprange In Worksheets("YTD").Range("b2:b117")
For Rno = 2 To 117
Svalue = "B" & Trim(Str(Rno)) 'cell reference of employee name from
Master "YTD" sheet
OValue = "C" & Trim(Str(Rno)) 'cell containing overtime of employee in
each sheet
If Trim(Tmprange.Value) = Trim(Worksheets("Oct07").Range(Svalue)) Then
Worksheets("YTD").Cells(Tmprange.Row, Tmprange.Column + 1).Value
= Trim(Worksheets("Oct07").Range(OValue))
End If
If Trim(Tmprange.Value) = Trim(Worksheets("Nov07").Range(Svalue)) Then
Worksheets("YTD").Cells(Tmprange.Row, Tmprange.Column + 2).Value
= Trim(Worksheets("Nov07").Range(OValue))
End If
If Trim(Tmprange.Value) = Trim(Worksheets("Dec07").Range(Svalue)) Then
Worksheets("YTD").Cells(Tmprange.Row, Tmprange.Column + 3).Value
= Trim(Worksheets("Nov07").Range(OValue))
End If
If Trim(Tmprange.Value) = Trim(Worksheets("Jan08").Range(Svalue)) Then
Worksheets("YTD").Cells(Tmprange.Row, Tmprange.Column + 4).Value
= Trim(Worksheets("Jan08").Range(OValue))
End If
Next Rno
Next
End sub

I know that this code looks non-generic and naive(I have a very basic
knowledge of VBA);

The problem you will see is that I will have to add a new statement every
time a new sheet is created.

Is there a better and efficient method or solution for this problem?
 
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
Concatenate Column C in multiple sheets into single sheet. ant1983 Excel Discussion (Misc queries) 3 October 26th 07 11:08 AM
copying one cell in multiple sheets into a column on one sheet LeahR Excel Worksheet Functions 3 June 1st 07 05:55 PM
to make a single row record become multiple row records AskExcel Excel Worksheet Functions 0 February 24th 06 09:46 AM
Multiple sheets as data for a single sheet Newbie1092 Excel Worksheet Functions 1 December 19th 05 05:20 PM
Single list from multiple sheets Brian H Excel Worksheet Functions 1 November 12th 04 09:21 PM


All times are GMT +1. The time now is 01:23 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"