Selecting Multiple Cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When you are in an excel file you can select multiple cells my clicking in
the first cell and then dragging across or down to the last cell, or by
Control + Click. Is there a was for me to pick several cells from inside a
VBA project. The main problem is that I don’t know which cells I want to
select. The program runs though looking for matches to cells in the first
column and then when it finds one it is suppose to select the next 5 cells in
that row.
Thank you very much for the help,
Jordan
 
set rng = cell.Find("ABCD")
if not rng is nothing then
set rng = rng.Resize(1,5)
' or if you don't want the found cell
' set rng = rng.offset(0,1).Resize(1,5)
rng.Select
end if
 
Jordan,

Assuming that the cell you find is active, you can use

Activecell.Resize(1,5).Select

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
typo:
set rng = cell.Find("ABCD")
should be

set rng = cells.Find("ABCD")

but that was just a "placeholder" for the code you are using.
 
try this vba programm("g" is your match)

Public Sub test()
Range("a1").Select

Cells.Find(what:="g").Activate
Dim lastcell As Range
Set lastcell = ActiveCell.Offset(0, 5)
Dim myrange As Range
Set myrange = Range(ActiveCell.Offset(0, 1), lastcell)
myrange.Select

End Sub
 
Just an example, finds a cell containing "a" and
then selects that cell + additional 5 cells down that row.

For Each c In Sheet1.UsedRange.Cells.End(xlUp)
If c.Value = "a" Then
Range(c.Address & ":" & c.Offset(5, 0).Address).Select
End If
Next


Sharad
 
Awesome, thanks a lot

Tom Ogilvy said:
typo:
set rng = cell.Find("ABCD")
should be

set rng = cells.Find("ABCD")

but that was just a "placeholder" for the code you are using.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top