Editing a VBA code to remove input box

ladbroke

Board Regular
Joined
Jun 2, 2006
Messages
175
Office Version
  1. 365
Platform
  1. Windows
I found a code online that works when done manually, but there is one little bit of it I'd prefer to change but I can't figure out what to remove to make it work. I've tried to study the code but to no avail. I've tried to break it down and see what works and what doesn't, but it breaks it.
Please help.

I want to remove the input box that asks what cell range I am wanting to select and basically ask it to select column CC (entire column that is) automatically without me needing to select it every time.

I imagine I am going to look silly but it really would be much appreciated.

VBA Code:
Sub SelectCellsWithData()
Dim bCell As Range
Set myRange = Application.Selection
Set myRange = Application.InputBox("choose one range that you want to select:", "SelectCellsWithData", myRange.Address, Type:=8)
For Each myCell In myRange
    If myCell.Value <> "" Then
        If bCell Is Nothing Then
            Set bCell = myCell
        Else
            Set bCell = Union(bCell, myCell)
        End If
    End If
Next
If Not bCell Is Nothing Then
    bCell.Select
End If
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I've figured it out.
I was deleting more than I should have.

VBA Code:
Sub SelectCellsWithData()
Dim bCell As Range
Set myRange = Application.Selection
Set myRange = Range("CC:CC")
For Each myCell In myRange
    If myCell.Value <> "" Then
        If bCell Is Nothing Then
            Set bCell = myCell
        Else
            Set bCell = Union(bCell, myCell)
        End If
    End If
Next
If Not bCell Is Nothing Then
    bCell.Select
End If
End Sub
 
Upvote 0
You don't need to Select anything to work with it !
And I wouldn't reference an entire column either....
Try
VBA Code:
Sub SelectCellsWithData()
Dim myCell As Range, bcell As Range, lr As Long
lr = Cells(Rows.Count, "CC").End(xlUp).Row
For Each myCell In Range("CC2:CC" & lr)
    If myCell.Value <> "" Then
        If bcell Is Nothing Then
            Set bcell = myCell
        Else
            Set bcell = Union(bcell, myCell)
        End If
    End If
Next
If Not bcell Is Nothing Then
    bcell.Select
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,384
Members
448,956
Latest member
JPav

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