PDA

View Full Version : Macro help!



Ron99
04-02-2011, 02:41 AM
Hi,

I have spreadsheet for each employees, there are three tabs

first employee - Ron, his table looks this way

SL #

Activitystart dateend dateStatus1Improve GSC process2/2/20113/22/2011Pending2Budget 20113/2/20113/22/2011Pending





second employee - Sam, his table looks this way

SL #

Activitystart dateend dateStatus1KPI's for supply chain3/3/20113/15/2011Completed2Budget 20113/2/20113/22/2011Pending3schedule for branches3/12/20113/15/2011Pending




third employee - Shawn, his table looks this way

SL #

Activitystart dateend dateStatus1Improve GSC process2/2/20113/22/2011Pending2Budget 20113/2/20113/22/2011pending





I need to consolidate the above data in one sheet as masterfile, this way

SL #

Activitystart dateend dateRonSamShawn1Improve GSC process2/2/20113/22/2011Pending Pending2KPI's for supply chain3/3/20113/15/2011 completed 3Budget 20113/2/20113/22/2011PendingPendingPending4schedule for branches3/12/20113/15/2011 Pending





I need a macro, as and when the data is entered in the employee sheet, the master file should update on its own.

Please let me know if you have any question, appreciate your help

Thanks,
Ron....

mdmackillop
04-02-2011, 02:47 AM
Hi Ron
Welcome to VBAX
You can post a sample workbook using Manage Attachments in the Go Advanced reply section. Can you show sample data and the desired result?
Regards
MD

Ron99
04-02-2011, 02:54 AM
Hello....

Thank you!!

I have attached a sample spreadsheet

mdmackillop
04-02-2011, 03:12 AM
Without a macro, in E2 enter
=IF(ISNA(VLOOKUP($B2,INDIRECT("'" & E$1 & "'!$B:$E"),4,0)),"",VLOOKUP($B2,INDIRECT("'" & E$1 & "'!$B:$E"),4,0))
copy across and down

Ron99
04-02-2011, 04:00 AM
Hi,

Thank you for the reply!!

I still have one problem, in masterfile the formula works under column E, F and G..thats awesome!! ...unfortunately doesnt meet my requirement

For example :- I have added a field under RON, but I dont see anything under masterfile, Its blank.

I want the field

3prepare roq3/2/20113/22/2011Pending

(entered under the tab Ron)

which I have entered under Ron..to be automatically updated in masterfile. unfortunately its blank.. I have updated the spreadhseet with the recent formula..hope this explaination helps!

mdmackillop
04-02-2011, 04:20 AM
For something like this to work, you need consistent activity names between the master sheet and all other sheets. This is best done by maintaining one activity list and using data validation to allow only those values to be entered. This would apply to Macros or Formulae.
With regard to Dates, I don't see how you can return conflicting dates from 3 sheets.
I think you should plan further the best way to insert new data and update existing.

Ron99
04-03-2011, 03:36 AM
I have a code which executes, but have two problems, the code executes only for 3 tabs but I want the code to execute for 10 tabs.

next problem is, in any tab when I enter it reflects in masterfile, but when I delete something in the tab, masterfile still shows the data.

I have attached spreadsheet, and also the code

Regards,
Vikas

mdmackillop
04-03-2011, 03:41 AM
There is no code in the workbook

Ron99
04-03-2011, 04:00 AM
Ooops!!! Sorry, had sent you the old file, please check it now

Thank you

mdmackillop
04-03-2011, 04:32 AM
Either you need to hard code your sheet names or otherwise organise/distinguish them so that Name sheets can be counted. This assumes Name Sheets follow the Master sheet and there is a final "extra sheet" as per your example. BTW, If you got your code at another site, please give a link to that location (http://www.excelguru.ca/node/7), and a link there to this thread.

Private Sub Worksheet_Activate()
Dim Wsht As Variant
Dim Rng As Range, Dn As Range, n As Long
Dim Sh As Integer
Dim Col As Integer
Dim Shts As Long
Dim i As Long


Shts = Worksheets.Count - 1
ReDim Ray(1 To Rows.Count, 1 To 4 + Shts)
Ray(1, 1) = "SL#": Ray(1, 2) = "Activity": Ray(1, 3) = "Start Date"
Ray(1, 4) = "End Date"

For i = 2 To Shts
Ray(1, 3 + i) = Sheets(i).Name
Next

n = 1
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Sh = 2 To Shts
With Sheets(Sh)
Set Rng = .Range(.Range("B2"), .Range("B" & Rows.Count).End(xlUp))
End With
For Each Dn In Rng
If Not .Exists(Dn.Value) Then
n = n + 1
.Add Dn.Value, n
Ray(n, 1) = n - 1
Ray(n, 2) = Dn
Ray(n, 3) = Dn(, 2)
Ray(n, 4) = Dn(, 3)
Ray(n, Sh + 3) = Dn(, 4)
Else
Ray(.Item(Dn.Value), Sh + 3) = Dn(, 4)
End If
Next Dn
Next Sh
End With
With Sheets("Master File")
.Range("A1").Resize(n, 4 + Shts) = Ray
End With
End Sub