I am looking for the best way to "link" two worksheets together. I have a main worksheet where information and data is added and then I would like to have two basic worksheets that draws columns from main spreadsheet. Whenever changes are made to the main sheet, they will also occur in the other two sheets. I was thinking of trying to activate a macro which automates hitting ctrl or shift and the two tabs like the below
sheets (Array("Main", "Summary")).select
But this failed to work as well. Its too much information for vlookups or anything like that so if anyone knows a way to have changes that occur in one sheet effect multiple other ones it would be much appreciated.
Thanks!!!
You have the worksheet.Change event for that. Something simple like the following:
Private Sub Worksheet_Change(ByVal Target As Range)
ThisWorkbook.Sheets("sheet2").Cells(Target.Row, Target.Column).Value = Target
End Sub
Will copy the value on every cell change from one sheet to another (the code goes in the sheet's private module).
Related
I found a way to highlight row when cell is selected. I would like to use it in every excel file I open but there is a problem. There are two steps. First, I have to create conditional formatting. Second, create a simple macro in the active sheet, not a normal module or personal.
My idea is that I create a personal macro that will do the first step (cond. form.) and then somehow create THE macro in the active sheet. But I don't know how.
Is it even possible?
This is the code I need to put into active sheeet module.
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Target.Calculate
End Sub
Thanks.
I have a code which looks like this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Me.sheets("WAM Data").Range("BY5:HW35").Interior.Color = Me.sheets("WAM
Exception").Range("BO7:HM37").Interior.Color
End Sub
But its giving error in code.
What I want to do is, change the cell formatting (color) of "BY5 to HW35" as "BO7:HM37".
If anyone could help that would be great.
You can delete me. and use only Sheets..., or use ActiveWorkbook.Sheets.. to refer to the activeworkbook, or ThisWorkbook.Sheets... to refer to the workbook the macro is run from, or Workbooks("name").Sheets... to choose whichever workbook you want from the ones you have open.
However, your macro will just run on first click of a mouse, regardless where that happens on your spreadsheet, with no conditions add to it... is that what you want to do with your code?
I have a worksheet where in the first three columns (A,B,C) I store data. These values are used in a macro.
I would like to know how it is possible to make this macro run automatically after data is pasted onto these columns. I am almost sure that I will use the Worksheet-Change module, but as for the code I am clueless.
Thanks in advance.
A simple implementation:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:C" & ThisWorkbook.Worksheets(1).UsedRange.Rows.Count)) Is Nothing Then
'Call your Macro to do stuff
End If
End Sub
Intersect checks if Target is in the range you want to monitor. So if something changes in columns past C, Intersect will return Nothing and your macro won't be called. Just keep in mind that the Worksheet_Change event fires on any change, even double clicking into the cells. If all you are doing in this Worksheet is copy&pasting data and then running your Macro, this should be fine, but if you are manipulating your data further, you might have to look at more sophisticated solutions. Examples include mirroring your Worksheet and comparing it pre/post Worksheet Changed Event. You can read more on this here: Detect whether cell value was actually changed by editing
I use MS Excel 2007 to make Bills and Quotation. Often I need to reuse previous quotation.
After I copy a quotation and paste it to new location the row height needs to be readjusted for each row.
is there any solution to this?
I'm not totally sure if this is what you are after. But have you tried something like this?
Private Sub Worksheet_Change(ByVal Target As Range)
' Here you enter a matrix with the cells you want to trigger a Autofit
' If you just want one column to do it, take Range("A1:A200")
Range("A1:C11").EntireRow.AutoFit
End Sub
This code gets the row-size auto-fitted everytime you change the value in the choosen cells.
It's hard to come up with a good solution when you do not give to much information.
Check here :
Excel Worksheet_Change Event not working if my code didn't help you.
Best Regards
I have an Excel doc that starts with some fields that come from calculations done on the rows below it. To do the calculations I currently have a module with about 4 functions that loop through rows 20 through N(first blank cell). These functions are called straight from the cells at the top of the sheet. The problem is that the calculations at the top are not updating whenever someone adds/removes data from the rows below. How can this be accomplished?
If your functions are Excel VBA user-defined functions called from worksheet cells, then you will get this not-recalculating behaviour if the UDF refers to cells that are not in the input parameters of the UDF.
If this is the case a good solution would be to define some Dynamic Named Ranges that expand/contract as data is added/deleted and use them as input to the function.
Another solution would be to add Application.Volatile to your UDF, but this has the undesirable side-effect that your UDFs will be recalculated at every calculation which can be painfully slow.
If I understand your question correctly, you can use Worksheet_Change event to accomplish such tasks.
In your sheet module, add a Worksheet_Change event:
Private Sub Worksheet_Change(ByVal rngChanged As Range)
' Call your subs and functions here
MsgBox "You just changed something!"
End Sub
Note that the Worksheet_Change sub must have one and only one argument of type Range. Excel will make it a reference to the range that was changed by the sheet user. If you want to observe its behaviour, try placing this line in the sub:
rngChanged.Interior.ColorIndex = 4
Read more e.g. here.