I have a macro that does this
ThisWorkbook.Worksheets("data").Range("A50").End(xlToRight).Select
which moves the view to a column way far to the right (so the user doesn't have to scroll, since its common to want to go there)
and I want another button that exists on the spreadsheet (as an image) to move above that spot when clicked (which would navigate back).
I tried cut and paste like
ActiveSheet.Shapes.Range(Array("Picture 23")).Select
Selection.Cut
ThisWorkbook.Worksheets("data").Range("A50").End(xlToRight).Offset(-2,0).Select
ActiveSheet.Paste
but that just pastes the image, there is no longer a macro associated with it.
By playing around with record macro I noticed that this happens when I move the picture around
Selection.ShapeRange.IncrementLeft -607.8260629921
but I don't know how to make that variable. what is that 607, pixels? if so, is there a way I can derive the "length" from a known cell to the active cell?
The place I'm navigating from, the first button, is static.
Dim rng as Range
With ThisWorkbook.Worksheets("data")
Set rng = .Range("A50").End(xlToRight)
rng.Select
With .Shapes("Picture 23")
.Top = rng.offset(-1,0).Top
.Left= rng.Left
End With
End with
Related
I have an excel file with hundreds of macros, where which macro has extensive code.
I need to change the layout of the cells and that includes moving some cells to another location.
My only problem is that after doing that i need to change the macros that interacts with that cell. Interacts as his value/formula was changed or his value is used in another operation
I can't search in the code for range("C2") for example because the cell can be affected in diferent forms like:
Range("C2")
Cells(2, 3)
Range("B1:E5")
Range(Cells(1, 1), Cells(10, 10))
Offset
Is there any whey that i can discover which macros are changing a specific cell?
Are you looking for a way to track a specific cell, or for a way to track all cells affected by VBA code? Also, "affected" as in "value was changed" or "formula was changed", or "cell was merged with another", "range was unmerged", or "borders were changed", or "backcolor was changed"? Is adding conditional formatting "affecting" a cell? Data validation?
And then, there are more ways a cell can be "affected", too. Without tracking the code as it's running, it could be hard to tell whether this myRange variable is affecting the cell you're looking for.. especially if methods like Range.Offset and Range.Resize are used.
Then ranges can be named, so Range("Foo") might be referring to a cell you're interested in, but you can't know that without verifying whether Names("Foo").RefersToRange includes that cell.
Short of carefully reviewing the code, I'm afraid you can't.
If no macro is highlighting any cell in bright yellow, you could always make a copy of the file and then handle Workbook_SheetChange in ThisWorkbook:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Target.Interior.Color = vbYellow
End Sub
You can easily add conditional logic here to only recolor modified cells from a specific sheet, or from a specific column or row.
Now remove or comment-out any Application.EnableEvents toggling everywhere in the code, and run your macros - the cells it affected (assuming a change in value is what we're after) should all be bright yellow.
If you need to know what code caused this, you can place a breakpoint there, and inspect the call stack:
I have a problem with excel in full screen mode. When I chose another sheet (via macro) and go back to previous sheet (via macro) I cant write something to cell selected cell. Any advice?
My code for fullscreen:
Private Sub Workbook_Open()
Application.DisplayFullScreen = True
Application.CommandBars("Full Screen").Visible = False
End Sub
My macro code for select sheet:
Private Sub skok()
Sheets("Sheet 2").Select
End Sub
I can testify that this problem is happening to my workbook also!
To improve visibility, I make the workbook go fullscreen with the DisplayFullscreen=True in the same sub.
Later, the user can move to Sheets 2 with macro in a command button. On sheet 2 there is a button "Save & Return" which runs a macro like
Sheets("Sheet1").select
But when we return to Sheet1 the cells seem to freeze. But the command buttons still work.The situation can be 'unlocked' when I randomly select another sheet below on the sheet tab. Then returning to Sheet1 I can then enter in the cells!
One strange thing is that although the sheet seem freeze, I can still copy & paste text in a cell using the Ctrl+C & Ctrl+V on keyboard.
I have the same problem, and it is an Excel bug! We can still copy/paste values in cells, write in cells by VBA code, but we cannot edit cells' value anymore by double-clicking the cell (or F2). The cell edition is frozen! (It is like unchecking the option "Allow editing directly in cells" (Options->Advanced options-> (Sector)"Editing options".)
To create the bug:
Click on an ActiveX control while you are in full screen mode (Application.DisplayFullScreen = True)
...and the bug is there now you cannot edit cells anymore!
The bug stays as long as the formula bar is not physically visible on your screen (fullScreen or not) and will STOP (as long as you do not recreate the bug...) as soon as the formula bar is displayed (staying in fullScreen and executing "Application.DisplayFormulaBar = True" won't work)
The bug will "temporarily" stop (with hidden formula bar) if you activate another sheet but will start again if you click on any other ActiveX control in any sheets (fullScreen or not)...
The answer is a good lesson in form. Try to avoid .Activate and .Select. If you always specify your ranges you can avoid situations like this with multiple workbooks. Use the format:
Workbooks("myBook.xlsx").Sheets("Sheet1").Range("A1").Value = "whatever"
or:
with Workbooks("myBook.xlsx").Sheets("Sheet1")
.Range("A1").Value = "A"
.Range("A2").Value = 2
.Range("A3").Value = "Blah"
End With
I am using the following macro to "reset" a form. It leaves selection lines on the areas on Range(C3:C4) and Rows(32:37). However, they don't seem to be "real" selection lines. If I click somewhere else on the sheet, they don't disappear. If I make a selection that includes these areas and then click out, they do disappear. I want it to stop!
For Each cl In Range("B12:B16")
cl.Value = 0
Next cl
For Each rw In Range("B26:B37")
rw.EntireRow.ClearContents
Next rw
'Clear Vendor/PO
Range("C3:C4").ClearContents
First off you don't need to loop:
range("B12:B16").Formula = 0
Rows("26:37").Clearcontents
Range("C3:C4").ClearContents
Can you post a screenshot of the issue you are experiencing, i can't really understand that they stay sort of selected, is there some conditional formatting on them that marks them a grey colour if empty or something?
If the ShrinkToFit property for an Excel worksheet cell is set to True, Excel shrinks the font size to fit all the text if necessary.
Is it possible in VBA to detect if the font size for such a cell has been shrunk? Easy to see it happen with my eyes, but I need to detect it with VBA.
Please note I am NOT asking how to check whether the ShrinkToFit property has been set to True. Nothing could be easier than that. I'm asking how to check whether the font size for the cell has actually been shrunk, which only happens if necessary to fit all the text.
I didn't find a solution and decided to go a different direction. However, since then I've had this idea, which I've not tested:
Make a hidden sheet or workbook, and copy the cell to a cell there. Copy the column width too. Turn Shrink to fit OFF on that worksheet. Check the column width. Now do an autofit on that column. Now check the column width again. Did autofit widen the column (again, with ShrinkToFit turned off)? If so, then I think it's a safe bet that it's shrunk in the original.
This is an example to check ShrinkToFit, considering Cell A1 in Sheet1 in this example:
Sub test()
Dim rngRange As Range
'Assign Range
Set rngRange = Sheet1.Range("A1")
'Set shrinkto fit as true
rngRange.ShrinkToFit = True
'Check whether cell is Shrink to fit or not
If rngRange.ShrinkToFit Then
'Set Shrinktofit as false or do something
rngRange.ShrinkToFit = False
End If
End Sub
This is one that's been killing me and I've tried almost every solution on the Internet.
Here's background. I have an HR model that has each department broken out on separate tabs. I want to run an extract from our payroll system each payroll run and send highlight any updates individually. If someone's title or salary or status changes, I want to have that called out by highlighting the cell.
Each tab uses an INDEX/MATCH lookup to the extract tab to pull in the current information. What I want is if any value changes or is new(new hire, for example), highlight the cells.
I've played with Worksheet_Calculate and Worksheet_Change to no avail. Worksheet_Change doesn't fire because I'm not making the change directly on the sheet and Worksheet_Calculate doesn't have the Target object for to reference. I've tried the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim updatedCell As Range
Set updatedCell = Range(Target.Dependents.Address)
If Not Intersect(updatedCell, Range("A:A")) Is Nothing Then
updatedCell.Interior.ColorIndex = 3
End If
End Sub
The range I actually need evaluated is A7:R104 but I've been trying to get anything to work when linked to another sheet.
This works fine if formula of target cell is pointing to another cell on same sheet. The moment you point to one on another sheet it doesn't work. I've tried most of the solutions on here with no success. I've even tried putting the Worksheet_Change on the extract sheet and see if I can trigger it that way with no luck.
Is there a recommended solution to triggering a change to a cell for a formula linked to another sheet?
so I just saw this post, I don't know if you've found the solution or are still looking, but:
if you select a cell in sheet 3, you can then go to the home tab, go to "conditional formatting" -highlight cell rules - more rules (at the bottom) - and "use formulas to determine which cells to format" and then put your cursor in the formula box. now, select a cell in sheet 1 (click the sheet1 tab, and click a cell) and you'll notice it should populate the address for sheet1, and the cell u selected. now type <> after that cells address, then select sheet2 and a cell. then click format, and choose a fill color. then ok. if you go to conditional formatting and manage rules it will show there the rule / formula and which cells it applies to.
doing this i was able to select cell D10 in sheet 3, and make it an ugly green if cells in sheet1 and 2 didnt match (I picked which cells) you can also select a range of cells.
thusly, you can apply this rule to whatever dells you want, and if you record a macro of you setting this conditional formatting, you can manitpulate that macro to apply it to a bunch of different cells, and change the ranges. (using loops / variables)