Name a range non-contiguous and then have option button put data in right most available

Caveman1964

Board Regular
Joined
Dec 14, 2017
Messages
121
I have totally butchered this.
I had working with a long drawn out "If" "else" and "isempty" code but its too much. I tried to figure out a better way but I cant get to work right.
I want to name g33 k33 o33 s33 w33 and aa33 and have the option button look for right most empty.
Here is my crap. (i named the range Noctwentyfour before I started...then added here because I couldnt get to work...now I've made a mess and need to start over)

Worksheets("Sheet10").Range("g33,k33,o33,s33,w33,aa33").Value = "Noctwentyfour"
Dim ws As Worksheet
Dim lastCol As Long
Dim rightmostEmptyCell As Range
Set noc24 = thisworkbook.Names("noctwentyfour").RefersToRange

lastCol = Noctwentyfour.Cells(1, noc24.Columns.Count).End(xlToLeft).Column

Set rightmostEmptyCell = Noctwentyfour.Cells(1, lastCol + 1)
rightmostEmptyCell.Select
If OptionButton1.Value = True Then ActiveCell.Value = "Vacuum"

Any help would be so appreciated.
 

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.
I have totally butchered this.
I had working with a long drawn out "If" "else" and "isempty" code but its too much. I tried to figure out a better way but I cant get to work right.
I want to name g33 k33 o33 s33 w33 and aa33 and have the option button look for right most empty.
Here is my crap. (i named the range Noctwentyfour before I started...then added here because I couldnt get to work...now I've made a mess and need to start over)

Worksheets("Sheet10").Range("g33,k33,o33,s33,w33,aa33").Value = "Noctwentyfour"
Dim ws As Worksheet
Dim lastCol As Long
Dim rightmostEmptyCell As Range
Set noc24 = thisworkbook.Names("noctwentyfour").RefersToRange

lastCol = Noctwentyfour.Cells(1, noc24.Columns.Count).End(xlToLeft).Column

Set rightmostEmptyCell = Noctwentyfour.Cells(1, lastCol + 1)
rightmostEmptyCell.Select
If OptionButton1.Value = True Then ActiveCell.Value = "Vacuum"

Any help would be so appreciated.
I finally got it figured out.
here is what i did

Private Sub OptionButton2_Click()
Dim ws As Worksheet
Dim targetRange As Range
Dim cell As Range

Set ws = thisworkbook.sheets("SOC")
Set targetRange = ws.Range("NOCtwentyfour")

For Each cell In targetRange
If IsEmpty(cell.Value) Then
cell.Value = "Vacuum"
Exit For
End If
Next cell
End Sub
Private Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,201
Messages
6,123,621
Members
449,109
Latest member
Sebas8956

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