Generating lists based off button press macros

MurdochQuill

Board Regular
Joined
Nov 21, 2020
Messages
84
Office Version
  1. 365
Platform
  1. Windows
Hi ladies and gents, I'm having trouble wrapping my head around how to do this, so im gonna take a shot at explaining


Basically, I'm trying to make a list from pushing buttons.
1620903151909.png

The unique identity will change, so will the suffix, but the button values will stay the same. I'm trying to look at the cell under "Identity", check that there's nothing in that cell, then paste "Hello-X" under identity when any button is pushed. If something is in that cell, it should move the whole paste to the next row. (For Identity, Value 1 and Value 2). When the button is pushed, it should also put the value shown on the button under Value 1 and Value 2.
FOR EXAMPLE: If 10,20 is pressed, then 1,7 is pressed it will do the following:
IdentityValue 1Value 2
Hello-X1020
Hello-X17


The Unique identity and uniqe suffix are able to be changed too:
1620903542794.png



If anyone can help me I will buy you a beer, It seems so simple but I'm new, so a solution for this & maybe a few pointers would be amazing!!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Ok, I've made assumption on cell addresses. You can edit to suit.

Typical button click code with applicable values.

VBA Code:
Private Sub CommandButton1_Click()
Call ButClicks(10, 20)
End Sub

1 off code to be called by all buttons to apply it's values.

VBA Code:
Sub ButClicks(V1, V2)

DatRow = Cells(Rows.Count, 2).End(xlUp).Row + 1

Cells(DatRow, 2) = Range("B3") & " - " & Range("D3")
Cells(DatRow, 3) = V1
Cells(DatRow, 4) = V2

End Sub

Hope that helps.
 
Upvote 0
Even though the original Q is sorted, how would I go about adding an exception to this, where if the cell it is going to paste on contains "x", "y" or "z", it will skip that row and go to the next one?
 
Upvote 0
Even though the original Q is sorted, how would I go about adding an exception to this, where if the cell it is going to paste on contains "x", "y" or "z", it will skip that row and go to the next one?
Q ? Sorry but I am not understanding enough to offer a solution.
Can you please illustrate or describe relative to your original images or use cell references?
 
Upvote 0
Q ? Sorry but I am not understanding enough to offer a solution.
Can you please illustrate or describe relative to your original images or use cell references?
Sorry! All good, I just mean you solved my problem with the original question.

I'm just adjusting your code to remove them as well, but if it encounters the "Identity" row where the headers are, it will remove that too. (Because I haven't told it where to stop).

VBA Code:
Sub Macro1()

DatRow = Cells(Rows.Count, 2).End(xlUp).Row

Cells(DatRow, 2).ClearContents
Cells(DatRow, 3).ClearContents
Cells(DatRow, 4).ClearContents

End Sub
 
Upvote 0
If your headers are in row 7 then include like...

VBA Code:
Sub Macro1()

DatRow = Cells(Rows.Count, 2).End(xlUp).Row
If DatRow = 7 then Exit Sub 'Do no more
'otherwise clear the last row
Cells(DatRow, 2).ClearContents
Cells(DatRow, 3).ClearContents
Cells(DatRow, 4).ClearContents

End Sub

The above will only do one row per run of the code.
You will need a loop if you want to clear all with one run of the macro ?
 
Upvote 0
Solution

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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