Scenario: I can't post the actual workbook due to sensitive materials but I'll explain it as best as possible.
Each Sheet is divided into branches i.e.: Sheet2 is Branch 2, Sheet3 is Branch 3 and so on.
For each sheet the column are the same.
Column A has the branch number in it.
Column B has irrelevant information so i just hide that column.
Column C has a system number (specific to each account.
Intention: I want to create another sheet called CallOuts.
I want to copy some rows (from various branches) and paste them onto the 'Master sheet' (CallOuts) I can work on the CallOuts sheet instead of going to each branch. So that whenever I edit a cell it will also update/change that exact same cell in the branch sheet and vise versa with the master sheet.
Problem: I know MS Exccel has a "Paste Special" function where it adds the cell. The problem with that is it links the cell# so if I sort the Master sheet it will replace the row into the wrong branch sheet.
E.g.: If System# J112 is in branch 2 sheet, row 2 and I have the link pasted in Row 4 in the master sheet, if I make updates on the Master sheet and then re-sort it and the System# now moves to Row 2 (on the master sheet) whatever is in Row 4(on the master) will now be in Row 2, Branch 2 sheet.
I was thinking maybe a macro where I could copy and paste the entire row from the master sheet. Do some type of case selection to check which branch is in column A and then find the same system # on the branch sheet then paste the whole row.
My VBA level is novice at best so any help would be appreciated.
OK, So I saw your attempt below. I am not sure how your code works but it seems like you were on the right track. However, I don't think the Case syntax is appropriate for this situation. You simply need a macro that will read what is in your "CallOuts" sheet and use that data to update your individual branch sheets. This macro should work for you:
Sub UpdateRecordsFromMasterSheet()
Dim wksht As Worksheet
Dim wkb As Workbook
Dim row As Range
Dim Row_to_Update As Range
Dim sysnum As Variant
Set wbk = ThisWorkbook
Application.ScreenUpdating = False
For Each row In Sheets("CallOuts").UsedRange.Rows
row.EntireRow.Copy
sysnum = row.Cells(1, 3).Value
For Each wksht In ActiveWorkbook.Worksheets
For Each Row_to_Update In wksht.UsedRange.Rows
If Row_to_Update.Cells(1, 3).Value = sysnum Then
Row_to_Update.PasteSpecial
End If
Next Row_to_Update
Next wksht
Next row
Application.ScreenUpdating = True
End Sub
This assumes you have your system number in column "C". So here is what I am imagining: Each time you assign an employee a bunch of rows - your employee updates those rows - and then you paste that data back into the "CallOuts" sheet. Then you run this macro and it will update the individual branch sheets based on what is in the "CallOuts" sheet.
If your a visual person here is how it will look:
Here is the updated callouts sheet:
Here is how the branches will look before the macro:
Here is the updated branch after the macro runs:
Try it out and let me know how it works. Note: this is just a start to show you how to do something like this - you could make this process more efficient by having the macro loop through the actual workbooks that the employees submit to you so you wouldn't have to copy and paste the data into your "CallOuts" sheet every time. Good Luck.
Related
I'm about as green as you can be with VBA. In a nut shell i have a report i run every month that shows me open files for my job. I have been doing this all on my own and I am trying to automate some of my sorting and cleaning I do to the list. We have 3 Sheets.
Worksheet 1: RAW Info (lists all of the open files I have in our system. We run this each month to make sure we don't lose anyone that has contacted us.
Worksheet 2: this is literally the worksheet that has most of the my conditional formatting, dropdown lists, ect.
Worksheet 3: "Final Sheet" that has all the cleaned up data. This workbook is exactly that a work book. I plan on doing the following once I get this issue cleaned up:
Copy to another workbook which has all of our other monthly reports in it. I am planning on having a cutton that will open the "Master" workbook, Add a new Tab, ask me to name that tab, and then copy the data I have just cleaned up. Adding the conditional formatting that we have in place already (so the conditional formatting will move to that workbook eventually).
So, back to where I am having issues; I want to take the input box I created, after the user data is entered, and turn that data into part of a macro, but I don't know how to do it.
For instance, when the user input box pops up, I can type in ("A1:E20"), and that will appear under a heading in Sheet 2 (Worksheet). But I then want that data for ("A1:E30") to be copied to Sheet 3 (Finished) in the correct location (in this case starting at ("E11").
What I am trying to figure out is if I type ("A1:E30") into the input box, and it places it on sheet 2, in Cell A12, what is the next part to get the parameters ("A1:E30") from Cell A12 into
The last code I had just copied Cell A12 from Worksheet to Worksheet Finished E11 as the same thing ("A1:E30") instead of going to Sheet 1 (RAW Data) and copying cells A1:E30 and starting it in Finished Sheet at cell E11.
I hope that this makes sense I am just stumbling and I feel like a fool.
Here is the code I have its horrible and clumsy at its finest.
Sub TEST_Module()
Dim rng As Range
Dim myResponse As String
myResponse = InputBox("Enter Range Here", " Final Copy Range")
Worksheets("Worksheet").Range("A12").Value = myResponse
MsgBox ("Copying" & myResponse)
To expand on Simon's comment:
Dim ws1 As Worksheet, ws3 As Worksheet, wb As Workbook, addr
Set wb = ThisWorkbook 'the workbook where this code is running
Set ws1 = wb.Worksheets("Sheet1") 'copying from here
Set ws3 = wb.Worksheets("Sheet 3") '...to here
addr = wb.Worksheets("worksheet").Range("A12").Value
ws1.Range(addr).Copy ws3.Range("E11")
I have a main sheet in which I manage my trades for currency on the FOREX. On that main sheet I have made buttons that I would like to hyperlink to the subsequent sheets that hold the daily data for each specific currency pair.
I am able to create a hyperlink to the sheet itself by using the hyperlink function but I want the hyperlink to actually find the first blank cell in column B and then count up 10 cells so that the last ten cells are visible on the sheet.
I have tried using Indirect, Offset, CountA, and Match combinations and variations to no avail. Please help.Main Screen Shot
Daily Sheet Screenshot
To simplify, you can replicate this code for each button. Change only one line for each button (and the subroutine name, of course)
Sub JPY_Daily_click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("JPY_Daily")
myrow = sh.Cells(sh.Rows.Count, 1).End(xlUp).Row - 10
sh.Activate
sh.Range("A" & myrow).Select
End Sub
I have a working spreadsheet with lists of items. One field could have 1 of 14 descriptions. I thought creating a macro would be quicker than manually going to a separate sheet and copying and pasting the desired description every time.
I am totally new to this, but was able to create a macro grabbing data in cell A1 in one sheet and adding that data to cell S3 in another sheet - see code below. (Each description has its own sheet with data in cell A1) My question is, how to move onto the next row and cell S4. Thanks in advance!
Sub Range_Copy()
Worksheets("Used Single Items Returns").Range("A1").Copy Worksheets("Gopher Items CSV Test").Range("S3")
End Sub
If you just want to copy into Col S on the selected row:
Sub Range_Copy()
Dim r
Set r = Selection.Cells(1).entirerow.range("S1") 'relative to row, not sheet
Worksheets("Used Single Items Returns").Range("A1").Copy r
End Sub
Let's say I have three sheets in Excel. Sheet 1 is the Master sheet, sheets 2 and 3 contain different sets of information with the same headers that feed into the table in the master sheet. Is there a way to make it such that I could edit information in sheet 1 and sheet 2 will change AND vice versa so I can edit info in sheet 2 that will update the master sheet?
You could solve it by having Vlookup-formulas in your Master sheet. That way, if you change anything in sheet 2 and 3 the Master will automatically be updated.
If the user changes anything in the Master sheet, you will have to build logic in VBA on that. One way to go is to format the Master sheet so that there is something that helps the VBA know what the formula should be in the edited cell, and also to know from where the data should come. Loosely one could set up the Master sheet like this:
Row 1 is hidden and contains the template formulas
Row 2 is hidden and is completely empty (this will make less problems with filtering)
Row 3 contains headers
Row 4 and down contains the data, using the formulas define in row 1
Add the Change event on the Master sheet, that sees if the changed cell was one with a formula. If so, it will examine the template formula to identify from where the data should come. Then it will update that cell in Sheet 2 or 3 with the new value that is entered in the Master sheet. After this, it will overwrite the value manually entered in the Master sheet with the formula from the template row.
The big job here is to write a parser that understands from which cell the vlookup will get it's value.
One thing that I overlooked is that the CHANGE event is triggered only ONCE if the user pastes several cells in one go. The TARGET will then contain several rows or columns.
So this is some kind of skeleton using the above idea...
Option Explicit
Dim ChangeEventDisabled As Boolean 'Flag for disabling the Change event
Public Sub Disable_ChangeEvent()
ChangeEventDisabled = True
End Sub
Public Sub Enable_ChangeEvent()
ChangeEventDisabled = False
End Sub
Sub Worksheet_Change(ByVal Target As Range)
Dim updatedValue As Variant
Dim SourceCell As Range
'While the MasterSHeet is populated intially, we don't want this event to do anything
If ChangeEventDisabled Then
'There are chenges being done in teh sheet that should not trigger updates of the source-sheets.
Else
'Only run the code if it was a data-cell that was changed
If Target.Row > 3 Then
'We are in the rows containg data
'Did the changed cell contain a Vlookup formula before the user changed the cells value?
If UCase(Cells(1, Target.Column).Formula) Like "=VLOOKUP(*" Then
'A vlookup normally populates this cell.
'To know from where the data normally comes, I will need to put back the formula in the changed cell.
'So, first save the new value that we will write in the source cell
updatedValue = Target.Value
'Insert the formula again in the cell
'As we will now CHANGE a cell in the Masterr sheet, a Change event will trigger. Disable it temporarily
Disable_ChangeEvent
Cells(1, Target.Column).Copy Destination:=Target
Enable_ChangeEvent
'Find out from which cell the data is being fetched by the Vlookup
Set SourceCell = MyMagicParsing(Target)
'Update the source-cell with the new value
SourceCell.Value = updatedValue
End If
End If
End If
End Sub
Function GetSourceCell(Target As Range) As Range
'This function should decipher the formula in the cell Target, and figure out from where
'the data is actually coming. It shoudl return the range which is the source of the data.
'As I dont know how to do that quickly, I just hardcode the cell that is the source.
GetSourceCell = Worksheets("Sheet2").Cells(67, 3)
End Function
I'm new to the visual basics language and would like some help in writing some codes. So I'm trying to write a program that imports data from a spreadsheet and shifts current data over. So I have a spreadsheet file with 3 sheets. I would first delete the data in the third and last sheet, then cut and copy the data from the second sheet over to the third sheet and the first to the second. and then prompt the user to select a data file to import to the first sheet. How do I go about doing this ????
Thanks
You can access each cell by using
Cells(row,column)
Where the row and column are both numeric. You can set the values like this
Cell(row,column) = "This is a new value"
You can access the values like this
aString = cells(row,column)
If you want to copy data from one worksheet to another, this code will copy the first twenty six columns and rows from worksheet 2 to worksheet 3...
dim row as integer
dim column as integer
For column = 1 to 26
For row = 1 to 26
'Copy worksheet 3 value to worksheet 2's value
Worksheets(3).cells(row,column)=Worksheets(2).cells(row,column)
'Clear worksheet 2's values
Worksheets(2).cells(row,column)=""
Next
Next
You could simply delete the third sheet by executing:
Application.DisplayAlerts = False
ActiveWorkBook.Sheets(3).Delete
Then insert a new sheet and place it before Sheet 1 and 2
ActiveWrokBook.Sheets.Add Before:=ActiveWorkBook.Sheets(1)
ActiveSheet.Name = "The New Name of your newly inserted sheet"
Then fill the sheet with any data that you may want to. You did not include any details in your question about what is the source of the data, so I guess, you already know about that.