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

Caveman1964

Board Regular
Joined
Dec 14, 2017
Messages
127
Office Version
  1. 2016
Platform
  1. Windows
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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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