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?
Related
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 new to VBA, and I have a sheet which has VBA macros assigned to shapes. It works fine on the same sheet, but when I copy and paste the shapes in the next sheet or create a new shape and assign the same macro it does not work. Kindly help me. Below is the code.
ActiveSheet.Shapes("CTSnext").Fill.ForeColor.SchemeColor = Black
Thanks for your response !!
However, Let me explain the issue.
In Sheet 1 I have 4 shapes Named
1) Cancelling the service
2) Next
3) Not interested
4) Reset
And all 3 shapes (2,3,4) will be in forecolor as white so it will be invisible.
When user clicks on "Cancelling the service" "Next" will appear (Meaning the fore color will change to black). And when "Next" is clicked "Not interested" will appear (Meaning the fore color will change to black). And when user clicks on "Reset" both "Next" & "Not interested" will turn into invisible (Meaning the fore color will change to white). Until now everything works fine.
Now i want to have a shape in Sheet 2 which says "Reset". So when user clicks on it the same function (Meaning the VBA of the "Reset" button in Sheet 1) should happen.
Below are the code.
For Cancel
ActiveSheet.Shapes("Next").Fill.ForeColor.SchemeColor = Black
For Next
ActiveSheet.Shapes("Notinterested").Fill.ForeColor.SchemeColor = Black
For Reset
ActiveSheet.Shapes("Next").Fill.ForeColor.SchemeColor = 1
ActiveSheet.Shapes("Notinterested").Fill.ForeColor.SchemeColor = 1
I hope i made myself clear, also i don't know to how to attach the excel file to this page so it will be helpful for you all to understand my need.
Thanks is advance.
Your line of code refers to one specific named shape (CTSnext). You replace that by shape number if you have only one in the sheet Shapes(0).
If you have several shapes on the current sheet and you want the macro to run on all shape, you can use a loop like
for each shp in ActiveSheet.Shapes
shp.Fill.ForeColor.SchemeColor = Black
Next shp
Following on from iDevlop's answer to loop through each Worksheet as well as each shape.
Dim wks as Worksheet
For Each wks in Me.Worksheets
For Each shp in wks.Shapes
shp.Fill.ForeColor.SchemeColor = Black
Next shp
Next wks
I have created a form in Excel. Based on how the user completes one cell, changes which cells they fill out next (for example: When filling out A10 if they answer "X" they will move to B1, if they answer "Y" they will move to B3.)
In order to guide the user through the form, I created a complex set of conditional formatting rules which will "highlight"(background fill) the next cell they need to fill out. Once they complete the cell the formatting on that cell goes away and switches to the next cell.
I have the conditional formatting working exactly how I want. My question is: Is there a way to have the active cell follow this same path. Either by setting up the same formula rules that guide the conditional formatting or is there a way to have a macro auto set the active cell to the "highlighted" cell from the conditional formatting?
Try this:
Private Sub Worksheet_Change(ByVal Target As Range)
Const NEUTRAL = 16777215
Dim r As Range
For Each r In Cells.SpecialCells(xlCellTypeAllFormatConditions)
If r.DisplayFormat.Interior.Color <> NEUTRAL Then
r.Select
Exit For
End If
Next
End Sub
Note: you can edit NEUTRAL at the top if non-highlighted cells have a different color than pure white.
Note: this assumes that the cell you want the selection to jump to is the only cell on the sheet that is highlighted with conditional formatting.
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
I have data from like A1:Z50 but I want to delete only A5:X50 using VBA
(I think it will be a lot faster than dragging the whole cell or using clickA5+shift+clickX50+delete).
How can I do this ?
And then, how to lock the cell to prevent it from getting fixed or cleared ?
You could define a macro containing the following code:
Sub DeleteA5X50()
Range("A5:X50").Select
Selection.ClearContents
end sub
Running the macro would select the range A5:x50 on the active worksheet and clear all the contents of the cells within that range.
To leave your formulas intact use the following instead:
Sub DeleteA5X50()
Range("A5:X50").Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.ClearContents
end sub
This will first select the overall range of cells you are interested in clearing the contents from and will then further limit the selection to only include cells which contain what excel considers to be 'Constants.'
You can do this manually in excel by selecting the range of cells, hitting 'f5' to bring up the 'Go To' dialog box and then clicking on the 'Special' button and choosing the 'Constants' option and clicking 'Ok'.
Try this
Sheets("your sheetname").range("A5:X50").Value = ""
You can also use
ActiveSheet.range
Not sure its faster with VBA - the fastest way to do it in the normal Excel programm would be:
Ctrl-G
A1:X50 Enter
Delete
Unless you have to do this very often, entering and then triggering the VBAcode is more effort.
And in case you only want to delete formulas or values, you can insert Ctrl-G, Alt-S to select Goto Special and here select Formulas or Values.