I used to use a nifty piece of code in Excel 2003 that could add buttons to a custom button bar:
Dim Magic8Ball As CommandBarButton
Set Magic8Ball = CommandBars("MyButtonBar").Controls.Add(msoControlButton)
Magic8Ball.FaceId = 1845
Magic8Ball.Style = msoButtonIcon
Magic8Ball.TooltipText =...
What I want to do is loop through all the shapes on a worksheet (for all worksheets in a workbook, I guess) and if they are textboxes, change some of the default formatting. I believe I have most of the code worked out, but am getting a runtime error that the object doesn't support being...
A1 formula: =5
B1 formula: =6
C1 formula: ="A1*B1"
D1 formula: ?
What sort of function could I put in D that would "execute" or "calculate" or "interpret" the C1 text into a formula that would return 30?
I know how to do it in VBA, but is there a formula that would be like:
=REFERENCE(C1)...
Crap -- it's:
ActiveSheet.HPageBreaks(1).Delete
Tried a whole whack of stuff, but this seems to work. When I tried this, I don't think I had HPageBreaks[1] set, so got a runtime error, but this works.
Sorry for the waste of time.
This seems simple enough:
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
How about removing one. I don't want to reset all as in:
ActiveSheet.ResetAllPageBreaks
I just want to get rid of the one, like:
ActiveSheet.HPageBreaks(1).Remove
But this doesn't work. Any...
Brilliant! Never thought of using InStr, even though I referred specifically to it, but didn't know of Join function until now. Nice touch with the extra commas on the front and back to get a true independent find.
Thanks so much!
Suppose I have made an array in VBA, something like:
ShirtCols = array("red", "beige", "white", "black", "blue")
MyCol = "pink"
I want to see if pink is an acceptable shirt colour as per this array (perhaps representing what I have in my closet right now). I could do:
for i = 0 to 4
if...
I want to loop through a selection, looping through the columns and then the rows.
"selection.rows" returns the array, which one can then tack on stuff like ".cells(1,1)" but how do I get the length of the array in rows and columns?
Thanks in advance as I know this should be pretty easy.
Rob, in this situation, you can just exit sub in the main code, but here's another idea that perhaps can extend this "problem" to greater application:
Private Function Check_Type(TestVar as Variant, Check as Boolean)
Dim <variables>
If TestVar Not <something> Then
Check = True
End If
End...
Wow, this works. So simple. MS so butt-backwards sometime - TextBox object doesn't work, but Control object does.
Anyway, aside from going into the details of my design, I have come across many instances where it would be useful to loop through controls without using 'for each ctrl in...
Well, I am in VBA, in UserForm1's code window, and whether I just use TextBox1 or Me.TextBox1 or UserForm1.TextBox1 it gives me a type mismatch.
Exactly:
Private Sub CommandButton2_Click()
Dim txtAction As TextBox
Set txtAction = Me.TextBox1
End Sub
Dim txtFirstName as TextBox
Set txtFirstName = UserForm1.TextBox1
Why doesn't this work? I've also tried using some vbObject type of stuff here, but I am fairly unfamiliar - is there an easy syntax fix for this?
Thanks again!
Cheers, Tom
The FAQ looks promising, I'm just surprised that one cannot use something like:
Sheets("Sheet1").Select
for:
TextBoxes("TextBox" & Num).Value
or even:
Sheets(16).select
for:
TextBox(Num).Value
I find many applications where it would be easier if I could reference in-VBA controls (such...
I have a UserForm with six groups of textboxes representing teams. For each team, a textbox holds "Team Name", "Coach's Name", "Number of Players", "Wins", "Losses".
What I want to do is loop through each group, like:
For myTeams = 1 to 6
TextBox(myTeams).Value = "Lakers"...
You don't need macro code at all:
Put this in column "C" and copy it down for all occupied rows:
=IF(ISERROR(VLOOKUP(B1&", "&A1,[Book2]Sheet1!$A:$A,1,FALSE)),"","x")
This part: B1&", "&A1
means take content of B1, merge the string "...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.