Help with VBA to have different function for a single macro butoon

Akw47

Board Regular
Joined
Nov 6, 2020
Messages
90
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
So my idea was based on the cell number. It would be the condition for the number of times my command button have to be clicked before the cell will get highlighted.
However I am unsure where to start, and have only come out with these


Private Sub CommandButton1_Click()

If ActiveSheet.Cells(3, 1) = 1 Then
rows(7).Interior.ColorIndex = 8
Else
End If

End Sub
Please assist me :( thanks
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi & welcome to MrExcel.
Is the button on a sheet, or on a userform?
 
Upvote 0
do you mean like the value of cell(x,y) then set color:

If ActiveSheet.Cells(3, 1) = 1 Then rows(7).Interior.ColorIndex = 8
If ActiveSheet.Cells(5, 1) = 2 Then rows(7).Interior.ColorIndex = 9
 
Upvote 0
Hi the button is on a userform. And I actually don't mean of changing the colour of the row, but the frequency of the button being pressed.
 
Upvote 0
Hi the button is on a userform. And I actually don't mean of changing the colour of the row, but the frequency of the button being pressed.
But my code, is just based on the sheet for the timebeing. will be on the userform in my futureworks
 
Upvote 0
How about
VBA Code:
Private Sub CommandButton1_Click()
   With Me.CommandButton1
      .Tag = Val(.Tag) + 1
      If .Tag = ActiveSheet.Cells(3, 1).Value Then
         Rows(7).Interior.ColorIndex = 8
         .Tag = 0
      End If
   End With
End Sub
This will only work on a userform, it will not work for an activeX button on the sheet.
 
Upvote 0
Solution
wow it works. Thanks so much :) Will ask you again when i add more things into the code, because I actually planning to do it for inventory scanning. But just started with button clicking first. Thanks again
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

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