PDA

View Full Version : [SOLVED] Stuck with defining range for calculation



Dancul
03-26-2019, 01:21 AM
Hello

I'm a bit stuck with find range from text and then make calculation with range ... What I mean

I need to find make some calculation. But I need to find start cell and end cell.

So my code looks:



Sub Vat()
Dim rng As Range, cell As Range

'Find text
DPHrange = Cells.Find("celkem s DPH").Offset(1, 0).Address


DPHrange2 = ActiveSheet.Range("F32").End(xlDown).Address

' It looks I'm stuck here> how can I set rnd to have range in rng
Set rng = Range(DPHrange, DPHrange2)

'The resto code is calculation
For Each cell In rng
Next cell
cell.Value = cell.Value * 1.21

大灰狼1976
03-26-2019, 01:29 AM
Hi Dancul!

Set rng = Range(Range(DPHrange), Range(DPHrange2))
or

Sub Vat()
Dim rng As Range, cell As Range, DPHrange As Range, DPHrange2 As Range
'Find text
Set DPHrange = Cells.Find("celkem s DPH").Offset(1, 0)

Set DPHrange2 = ActiveSheet.Range("F32").End(xlDown)
' It looks I'm stuck here> how can I set rnd to have range in rng
Set rng = Range(DPHrange, DPHrange2)
'The resto code is calculation
For Each cell In rng
Next cell
cell.Value = cell.Value * 1.21


--Okami

Dancul
03-26-2019, 02:32 AM
Hello Okami.

Thank you very much.

It is working perfectly. I was missing this code many times ...

Just one think if somebody want use it, the proper last part of the code is:



For Each cell In rngcell.Value = cell.Value * 1.21
Next cell