Creating multiple button using a loop, need help with height

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
I have a bit of code that works fine if I want to fill a cell with a button, but for my next venture into buttons I would like to make the height span two cells.
As an example
A5:A6 is a button
A7:A8 is a button
A9:A10 is a button
A11:A12 is a button

I can't figure out how to edit the loop to skip a row

VBA Code:
    Dim var As Variant
    Dim m As Long
    
    var = Array("Sales", "Service", "Parts", "All")
    
    For m = 0 To 3
    With ActiveSheet.Buttons.Add(Range("A" & m + 6).Left, Range("A" & m + 6).Top, Range("A" & m + 6).Width, Range("A" & m + 6).Height)
        .OnAction = "Dept" & (m)
        .Characters.Text = var(m)
        .Name = var(m)
        .Placement = xlFreeFloating
    End With

Would I add something like
Range("A" & m + 6 & ":A" & m + 7)

Thank you
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You could use:

VBA Code:
With ActiveSheet.Buttons.Add(Range("A" & m + 6).Left, Range("A" & m * 2 + 6).Top, Range("A" & m + 6).Width, Range("A" & m * 2 + 6).Height + Range("A" & m * 2 + 7).Height)
 
Upvote 0
Solution
You could use:

VBA Code:
With ActiveSheet.Buttons.Add(Range("A" & m + 6).Left, Range("A" & m * 2 + 6).Top, Range("A" & m + 6).Width, Range("A" & m * 2 + 6).Height + Range("A" & m * 2 + 7).Height)
That worked perfectly, thank you. Now I just need to figure out what is happening. :)
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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