Display Text when Button is checked

eagerbeav3r

New Member
Joined
Feb 24, 2022
Messages
14
Office Version
  1. 365
Platform
  1. Windows
i dont seem to make progress bcs I dont have experience. Maybe you guys can help me out.

If a button is checked i want it to display the text in a free cell from A1 to A14. I tried .TypeText „…“ but that does not work.

Help is much appreciated
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
So put "the text" in an empty cell between A1 and A14, otherwise do nothing?
Perhaps put this between the beginning and end of your button click event. Note that Range reference may not work as written - depends on where you put this code. You might have to further qualify it such as Sheets("yourSheetNameHere").Range("A"& i)
VBA Code:
Dim i As Integer

For i = 1 to 14
  If Range("A" & i) = "" Then
    Range("A" & i) = "the text"
  End If
Next
 
Upvote 0
So put "the text" in an empty cell between A1 and A14, otherwise do nothing?
Perhaps put this between the beginning and end of your button click event. Note that Range reference may not work as written - depends on where you put this code. You might have to further qualify it such as Sheets("yourSheetNameHere").Range("A"& i)
VBA Code:
Dim i As Integer

For i = 1 to 14
  If Range("A" & i) = "" Then
    Range("A" & i) = "the text"
  End If
Next
Thanks for the reply. The code is working but it displays the text in every free cell ranging 1-14. Is there a way to only display it once in one free cell ranging 1-14?
 
Upvote 0
This should do that. Might not be what you really need if that code is contained within other code. In that case, use Exit For , not Exit Sub.
VBA Code:
Dim i As Integer

For i = 1 to 14
  If Range("A" & i) = "" Then
    Range("A" & i) = "the text"
    Exit Sub
  End If
Next
 
Last edited:
Upvote 0
Maybe this helps. As you see in the Picture below I got a Series of buttons. Each button will display different text to the Cells in A.
Is there a way to get the text of the button which is pressed first in A 1 the Second one in A 2.
It should depend on the order in which they are pressed rather than the button itself.

1646130104431.png


Because there are going to be more buttons i dont want the order to be set in stone.
 
Upvote 0
So now you want the button caption to be written to the next empty cell in column A, but do not go beyond A14? Then the only way I know how to do that in Excel vba is to have the same sub for each button.
VBA Code:
Dim i As Integer

For i = 1 to 14
If Range("A" & i) = "" Then
Range("A" & i) = ActiveControl.Caption
Exit Sub
End If
Next
 
Upvote 0
Solution
So now you want the button caption to be written to the next empty cell in column A, but do not go beyond A14? Then the only way I know how to do that in Excel vba is to have the same sub for each button.
VBA Code:
Dim i As Integer

For i = 1 to 14
If Range("A" & i) = "" Then
Range("A" & i) = ActiveControl.Caption
Exit Sub
End If
Next
Okay this solved it thank you so much. I kept forgetting to Exit the Sub, that was the Problem...
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,855
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top