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.
Related
I'm using the following formula in conditional formatting to highlight the active row when I click on a cell,
=OR(CELL("row")=CELL("row",A1))
and in VBA editor I am applying this macro to my worksheet.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Target.Calculate
End Sub
Currently I have to repeat the steps when I move onto the next worksheet (with existing data) and for some reason it doesn't always work. Is there a way to apply this to the entire workbook of current worksheets and possible new ones? Many thanks in advance!
condition formatting - new rule
VBA editor
Have you try placing the VBA into ThisWorkBook?
I do realise placing the VBA into ThisWorkBook generally works better and more accurate than worksheet. In the ThisWorkBook, you could call a specific worksheet to perform the VBA.
With sheets("NameOfWorksheet")
Target.Calculate
End with
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 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).
I'm using Excel 2010.
I added this code to my sheet and it works.
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1") > 0.5 Then
MsgBox "Discount too high"
End If
End Sub
But I want to create some way where I could create code and share that code across all excel workbooks on our network.
So I made a module and created an add-in and put the code INTO the module of the add-in.
I deleted the code from the sheet since I want the code to be accessible from the module.
I enabled the module.
And the VBA code doesn't work unless I put the code into the sheet. Please advise how I can just have this code in one file and have that code shared across all excel workbooks on our server.
You must put the Worksheet_Change under the Sheetname of the Excel Objects. So if it is Sheet1 that you want this procedure to run on, you will have to put it under Sheet1. If you want it to work on all sheets in the workbook, you will need to put it under ThisWorkbook AND you need to change the procedure name to Workbook_SheetChange
I tried running the private sub code:
Private Sub Worksheet_Calculate()
Dim target As Range
Set target = Range("G3")
If Not Intersect(target, Range("G3")) Is Nothing Then
End If
End Sub
I am pulling a value from one sheet and putting it into another cell on a separate sheet. I want the VBA to run when the cell is automatically changed. When I tried the code above, nothing happened when I updated the cell.
From the sounds of things the issue seems to be that you're trying to put the code in a Module like a regular macro. To have it run based on a worksheet event, you need to have the code in that worksheet's code window (in the VBA window, there's the "Microsoft Excel Objects" folder, inside is the list of worksheets, double-click the worksheet to open it's code).
Once you've opened the worksheet's code, at the top of the window you should see two drop-downs. The left one should show "(General)". In that drop-down select "Worksheet" (should be the only option).
In the drop-down to the right of that, select "Change". Then you need to validate the Target is the right cell (If Target.Address = "$<Column letter>$<row #>"). Inside that If statement is where you'd nest your code to copy the value to the second worksheet