Select range of cells, given the address of the first one on top

Alex Piotto

Board Regular
Joined
Jul 5, 2016
Messages
82
Office Version
  1. 2007
Platform
  1. Windows
Hi! Here we go...

From a ComboBox value in sheet1 i am trying to select a range in sheet2 , copy it and paste it in sheet1 in the right place.

sheet1 is named VENDAS
sheet2 is named DBase CLIENTES

I wrote a script, but i am stuck where i need to select the range below the selected cell in row1 (range named TUTTICLIENTI in DBase CLIENTES) while deselecting the first cell, from row2 down to row274.

VBA Code:
Private Sub ComboBox1_Change()

Application.ScreenUpdating = False

Dim miocliente As String

miocliente = Worksheets("VENDAS").OLEObjects("ComboBox1").Object.Value   'get client name from combobox

Dim foundRng As Range

ThisWorkbook.Sheets("DBase CLIENTES").Activate

Set foundRng = ThisWorkbook.Sheets("DBase CLIENTES").Range("TUTTICLIENTI").Find(miocliente)   'look in DBase CLIENTES, range TUTTICLIENTI for same string

If miocliente = "Seleccionar Cliente" Then

'do nothing

Else

If foundRng.Value = miocliente Then

ThisWorkbook.Sheets("DBase CLIENTES").Range(foundRng.Address).Select      'HERE THE CELL WITH THE same STRING IS SELECTED

End If

MsgBox foundRng.Address  'USEFUL TO VIEW THE ADDRESS

'NOW I NEED TO SELECT AND COPY THE RANGE BELOW THE SELECTED CELL IN ROW1 (FROM ROW2 down TO ROW274), IN THE foundRng.Address COLUMN) - HELP HERE!




'FINALLY I WILL PASTE THE COPIED RANGE INTO VENDAS - NO PROBLEM HERE HOPEFULLY...

'ThisWorkbook.Sheets("VENDAS").Activate
'ThisWorkbook.Sheets("VENDAS").Range("B5:C277").Select
'ThisWorkbook.Sheets("VENDAS").Range("B5:C277").PasteSpecial Paste:=xlPasteValues
'ThisWorkbook.Sheets("VENDAS").Range("B5:C277").Borders.LineStyle = xlContinuous
'ThisWorkbook.Sheets("VENDAS").Range("A1").Select

End If
    
Application.ScreenUpdating = True

End Sub

What to do? A bit lost here...
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
my own solution

VBA Code:
ThisWorkbook.Sheets("DBase CLIENTES").Range(Selection, Selection.Offset(274, 0)).Copy
 
Upvote 0
is ListfillRange='DBase CLIENTES'!A2:A278

and paste VENDAS A1 then A2 next A3 or move A1 below then paste ComboBox value into A1 to be new result up
 
Upvote 0
Is it Like this example?
VBA Code:
Private Sub ComboBox1_Change()

Dim Sht1 As Worksheet, Sht2 As Worksheet
Dim ComBx1 As Object
Dim miocliente As String
Dim FndRng As Range, FndRngs As Range
Dim TUTTICLIENTI As Range

Set Sht1 = ThisWorkbook.Worksheets("VENDAS")
Set Sht2 = ThisWorkbook.Worksheets("DBase CLIENTES")
Set TUTTICLIENTI = Sht2.Range("A2:A274")
Set ComBx1 = Worksheets("VENDAS").OLEObjects("ComboBox1").Object
ComBx1.List = Application.WorksheetFunction.Transpose(TUTTICLIENTI)
miocliente = ComBx1.Value
Set FndRngs = TUTTICLIENTI.Offset(-1, 0).Resize(TUTTICLIENTI.Cells.Count + 1, 1)
Set FndRng = FndRngs.Find(What:=miocliente, After:=FndRngs.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
            , SearchFormat:=False)
''''''''''''''''
    With Sht1
    LstRw = .Cells(.Rows.Count, "A").End(xlUp).Row
    .Range("A" & LstRw + 1).Value = FndRng.Value
    End With
    
End Sub
Select range of cells, given the address of the first one on top.gif
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,938
Latest member
Aaliya13

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