Determine Position Of Shape/Button On Worksheet
Jun 2, 2008
I have written a small piece of code that handles clicks on buttons on an excel spread sheet. When a button is pressed, i need to know the row number where the button resides in.
I have searched and read about this issue on several forums, and they all indicate that i need to use something like
application.caller.topleftcell.row
to get the row number and
application.caller.topleftcell.column
to get the column number.
However, when i use the row variant, it ALWAYS returns row number 1. When i use the column variant, it returns the column number it is actually in.
i have added the full code that is creating the buttons below, and also the part that displayes the rownumber that is incorrect.
Private Sub Workbook_Open()
Dim name
Dim time As Integer
time = InputBox("Typ the hour you are checking" & vbCrLf & "eg: 7, 10, 13, 14, 15, 16, 17, 18, 19", "Which Check")
View 9 Replies
ADVERTISEMENT
Apr 30, 2008
Add Multiple Buttons That Select Row Of Housing Cell. One of my Macro's places a button on a sheet using Top/Left;
Set sbut = Sheets("Listings").Shapes.AddFormControl(xlButtonControl, _
Range("J" & count).Left, Range("J" & count).Top, 50, 12)
When I try to find the row of the clicked button using the following code;
Range(ActiveSheet.Buttons(Application.Caller).TopLeftCell.Address).Activate
The code behaves differently in Excel 2002 and 2007. In 2002 it returns the row the button sits on, but 2007 returns the cell above the button. This could be because the workbook is an XLS running in Excel 2007 in compatibility mode? Is there a way to "nudge" the button down a little after it has been placed using .top/.left ? Or is the only way around this something like;
Range(ActiveSheet.Buttons(Application.Caller).TopLeftCell.Address).Activate
count = ActiveCell.Row
If Application.Version >= 12 Then
count = count + 1
End If
Is this a bug, or something that I am doing wrong ? The workbook needs to be a .xls to ensure that it works in older versions of Excel.
View 4 Replies
View Related
Oct 23, 2007
I am having trouble writing a macro that checks the value of an option button to change a string accordingly. The ActiveMonth variable is used to copy information across from one work sheet to another, with the worksheet depending on which of the option buttons is selected.
Static ActiveMonth As String
View 9 Replies
View Related
Aug 6, 2008
I am trying to cut and paste an object (an excel shape to be more precise) into its same position. It could, for example, be relative to the top left corner, but how to modify the paste method will be welcome. Surely this is a piece of cake for most of you, but I haven't been able to find the answer for objects floating on the screen.
View 5 Replies
View Related
Jul 10, 2014
I have an autoshape on an sheet, and use this code (it's a circle), to rezise it....
[Code] ....
However, it does rezise it, but the shape doesn't keep it's central position. Is there a bit of code I can add to stop the shape from moving? In other words, have the shape rezise around it's center of location?
View 4 Replies
View Related
May 7, 2012
I'm messing around with two shapes, a Cannon and Cannon Ball. With code the Cannon rotates for the angle of fire. What I can't do is position the Cannon Ball at the end of the Cannon when Cannon is at an angle. Long time since I was in school so forget most of my maths.
Code:
Sub IamUseless()
Rem this is work in progress and in NOT WORKING!!!!!!!
Dim xDistance As Double ' is inital x position of object
[Code].....
View 1 Replies
View Related
Feb 15, 2007
I created a shape (rectangle). I assigned a macro to it, to activate another worksheet.
Can I fix the position of the shape on the screen, near the top. I have 700 rows in the worksheet and I want this rectangle always visible, near the top.
View 4 Replies
View Related
Jan 15, 2008
i need to loop through a column of values and get each value
Dim LastRow2 As Long
Windows("SCFOutput.xlsm").Activate
Sheets("Q2SCNeg").Select
Columns("A:B").Select
ActiveSheet. Range("A65536").End(xlUp).Offset(1, 0).Select
LastRow2 = ActiveCell.Row - 1
For Each c In Worksheets("Q2SCNeg").Range("A2:A" & LastRow2).Cells
MsgBox ActiveCell.Value
Next c
i did this but it selects the first blank row (row 15) and gives me an empty message box 14 times (which is right, but i need 14 values) the reason i need the loop is because the number ov values will always change
View 2 Replies
View Related
Oct 13, 2013
I want to resize a shape and set the height to a specific cell. How can I achieve that?
View 7 Replies
View Related
Feb 11, 2010
I'm am trying to find some way to determine if a particular tab falls before/after/between other tabs in a workbook. For example, if I have a tab "Top" and a tab "Bottom", I want to be able to determine if tab X is between them.
View 14 Replies
View Related
Nov 19, 2008
I have map shape in my excel sheet. each country is a shapes on its own. If i Select one of the country i want to display a pop up Box. For examle if i select Americas I need it to display another box with some data and when i deselect it it should hide the box. Tried some code over here but does not work.
Sub HideShowRectangle()
With ActiveSheet.Shapes("Data1")
If ActiveSheet.Shapes("Americas").Select = "True" Then
.Visible = True
Else
.Visible = False
End If
End With
End Sub
View 5 Replies
View Related
Mar 7, 2008
I received this code from an example I found once upon a time that was originally submitted by someone else. Right now the code enters the current date in a cell of the same row as the checkbox when it's checked. I need to revise it, or come up with something similar, that will reference the value of a cell when it is in the same row as the button (from the Forms toolbar) that is clicked to activate the macro. First of all, I don't know how to reference a Forms button in VBA.
Sub Process_CheckBox()
Dim cBox As CheckBox
Dim LRow As Integer
Dim LRange As String
LName = Application.Caller
Set cBox = ActiveSheet.CheckBoxes(LName)
' Find row that checkbox resides in
LRow = cBox.TopLeftCell.Row
LRange = "B" & CStr(LRow)
'Change date in column B, if checkbox is checked
If cBox.Value > 0 Then
ActiveSheet.Range(LRange).Value = Date
'Clear date in column B, if checkbox is unchecked
Else
ActiveSheet.Range(LRange).Value = Null
End If
End Sub
Here is some other code I already created. Unfortunately, because I don't know how to do the row reference, I had to create 25 different macros, which just bulks up the size of my file and slows it down. But here is what I'm trying to accomplish in my macro:.............
View 8 Replies
View Related
Nov 11, 2008
I require a macro to enable a selected shape to be moved from current cell location to relative position but 1 row up. eg topleft address = A4 and shift shape to topleft address = A3
View 5 Replies
View Related
Dec 5, 2012
I really dislike the look of the command buttons and would like to use a nice flat-looking Shape into a functional button.
View 3 Replies
View Related
Feb 14, 2008
How do you references the properties of a shape? I am having trouble with 2 different types. Firstly, I have a worksheet with a group of commandbuttons (all added using the Control toolbox) and I want to loop through them changing, for example, the enabled property of each to TRUE.
Secondly, I have some commandbuttons on a worksheet (added using the Forms toolbox). How would I loop through changing, say, the text on the buttons. I used the macro recorder to try to get an idea and got the following:
Sheet1.Shapes("button 15").Select
Selection.Characters.Text = "New Text"
Although this works, it is not very elegant, how can it be achieved without selecting the button each time, but rather by directly accessing the property.
View 3 Replies
View Related
Feb 20, 2002
How do I insert a row using a macro button that insert the row beneath the row that the macro button is touching?
View 9 Replies
View Related
Feb 3, 2009
I have a button (group containing and add and delete button).
I want to identify the row (position of shape/button calling the macro) to enable inserting a new row (1 row down from current row).
Then do the same to delete a row (position of shape/button calling the macro) to enable deletion of selected row.
This will allow me to add/insert rows by the button located at that row
The problem i have is getting the row property (row position of the button eg. TopLeftCell.Row) of the add button. The add button (RowBtnAdd) is a shape within a group (BtnGrp)
I also note that when a group is copied, it has the same shape name as that copied.
I want to keep the add and delete shape within the group (BtnGrp).
I do not want to select a cell or row or enter a row number to delete etc.
refer to sample workbook attached. Currently only has one record row.
View 6 Replies
View Related
Jul 3, 2007
I'm trying to find out how can I fill a range of cells when clicking in a Command button in Excel. The process should be:
1) The user opens my XLS worksheet.
2) Goes to the next empty row and fill some specific fields
3) Then he should fill up 15 parameters on the right as Y or N
4) In case all of them are correct instead of going one by one typing "Y" I want he clicks in a button (with VBA code associated) and then 15 cells on the right should be filled with "Y" value
View 8 Replies
View Related
Nov 2, 2012
I have a bit of code that I saved as an add-in. The code does a couple things: (1) Creates a right-click button that on action (2) draws a rectangular auto-shape that is the size of any selected range.
The add-in seems to loaded correctly.
However, when I launch a new excel sheet, my intent was to have the code (the right click option) be available whenever I opened Excel.
Is there another step to accomplish this?
View 7 Replies
View Related
Feb 18, 2009
how can i define, in vba that after click on button in sheet1, it looks at value in cell B1 in this sheet and move my cursor exactly on this value in sheet2 where i have data in range (B4:C6000).
View 2 Replies
View Related
Jul 15, 2014
Is there any way to place a Control Tip for a shape on a excel worksheet?
View 3 Replies
View Related
Apr 18, 2008
This one has me baffled: I recorded a macro to add a shape to a worksheet, very simple. When I try and run it it comes up with a "The specified value is out of range" error. I've searched the net and it seems to come up where the file has been converted from an earlier version of excel (which this file has) but I haven't been able to find a work around for it. The relevant code is
With ActiveSheet
.Shapes.AddShape(msoShapeLeftArrow, 205.5, 312#, 144#, 23.25).Select
End With
View 3 Replies
View Related
Jan 1, 2008
I am working on creating an examination questions in Excel. I want to also build in formulas in the Excel sheet so that the answers will be calculated automatically as the candidates choose the answers. I have inputed an option button from the froms toolbox beside each answers for the candidate to click to indicate the answers. Is it possible to calculate the correct answer or wrong answer with a formula when the candidate clicks on the option button ? Is there a formula that I can use?
View 2 Replies
View Related
Sep 18, 2008
I've been trying to make use of 'Run "doit", but the macro stops when it gets to my sheets called 'RST' and 'RST Pivot'. What I'm I doing wrong?
Sub DoIt()
Application. ScreenUpdating = True
With Sheet1.Shapes("Rectangle1")
.Visible = msoTrue = (Not Sheet1.Shapes("Rectangle1").Visible)
End With
'Toggling sheets Forces Rectangle 1to show while code is running
Sheets("RST").Select
Sheets("RST Pivot").Select
End Sub
Also, do I need to change 'With Sheet1.Shapes' to reflect the actual sheet name?
View 3 Replies
View Related
Mar 22, 2008
In one column I want to reference the maximum value entered in another column. In a third column, I want to refernce a different row that is in the same column as the maximum value.
View 8 Replies
View Related
Aug 31, 2006
I'm creating a macro to select, modify dimensions and place shapes on a excel sheet. (I'm talking about pictures insered and stocked in a specific sheet of my workbook)
When the users insert a new picture he has to set a name for each of them.
A combobox contain the choices, when an item is selected, the macro identify, size and place the corresponding picture.
But I have a bug if a shape doesn't exist when I try to select it :
Sheets("fiche de controle").Select
'select the sheet with the pictures
ActiveSheet.Shapes(Item_old).Select
'select the shapes "Item_Old"
Item_Old is a variable corresponding to the picture name.
If the user made a typo, I have a bug.
Someone knows how to test if the shapes exist to display a meesage if not ?
Or somethig to avoid this kind of bug ?
View 6 Replies
View Related
Jun 4, 2009
I have a bit of a complicated one here so I have attached my book, its probably easier to undertstand the query by looking at the book. Hopefully somebody can help me out here.
I have 2 worksheets:
A results worksheet - this contains all category of results, each category has been given a specific sort id.
A foreign worksheet - this contains all categories found on the results worksheet with sort id = 7.
Now the complicated bit. The whole exercise is too pick up the correct exchange rate for the foreign category (sort id 7). each foreign type has a specific number at the end of its description in brackets e.g (3).
At the bottom of the "results worksheet" is a key which says what type of exchange rate to use for this type e.g. (3) Price of CAD 22.9 converted using exchange rate of CAD 1.9645 = £1.
What I need to do is on the foreign worksheet, it to recognise the number in the item description, keep it in mind then switch over to the "results worksheet" find the keys at the bottom of the page (the key is not necessarily in the same place all the time!!), match the number in the items description with the corresponding key and then find the exchange rate.
As i said very difficult to explain, since I reletively zero experience with this kind of work in excel. Luckily I been muddling my way through a work project gradually thanks to a forum member here. so i hope we can keep this up!
edit:
two restrictions in the way this solution can be done:
1- Results worksheet can not be modified, but it can be referenced to using INDIRECT, and you can make any number of modifications outside of the results worksheet.
2. Any solution must be automatic.
/edit
I have attached my workbook and highlighted the bits I need to fill and the picks I need to pick up.
Would be ever so grateful if some1 could show me the light here.
View 14 Replies
View Related
Oct 6, 2009
Part of my code adds a Worksheet to the selected Workbook and then re-orders them alphabetically, but one of the Worksheets (Called home) should always remain at position 1. Is there a way to dictate exactly which postion it should be in so that I can place it there after the sort is complete?
View 7 Replies
View Related
Mar 1, 2008
Using excel and Crystal Ball I generated a workbook that calculates via VBA Value at Risk and diverse financial charts and ratios.
I have a second workbook, the template, where this values are pasted generating a report.
Up to this point the macro works correctly, the problem is that some of the Crystal Ball charts are pasted as images and I dont know how to "handle" this images.
I reached the point where I can paste the image in the template.
I want the macro to:
1) Detect the images in the template worksheet
2) Determine a position and size for each image
View 4 Replies
View Related
Sep 7, 2006
I have a button on say, sheet1 with text that I want to change after a certain action takes place; however, I was trying to change this text without switching sheets. (switching sheets isn't a big deal, I'm mainly trying to do it my way for the practice). I'm able to select the button on the other sheet without actually switching sheets, but when it comes to changing it's text I get an error. Here is the code I tried:
Sub macro1 ()
Worksheets("sheet2").Select
Worksheets("sheet1").Shapes("Button 2").Select
Selection.Characters.Text = "Done"
End Sub
Problem with this is it gives cell A1 on sheet2 the "done" text. I also tried this...but it gives the error.
Sub macro1 ()
Worksheets("sheet2").Select
Worksheets("sheet1").Shapes("Button 1").Select
With Worksheets("sheet1").Shapes("Button 1")
.Characters.Text = "Done"
End With
End Sub
View 3 Replies
View Related