Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

Is there a way to express variables with a range of numbers to meet a loop condition in vba

$
0
0

Is there a way to express variable f as a range of numbers like for instance, f = 4 to 9 in excel vba? Because my intention here is to create a condition such that for i = 1 to lastColumn, if i falls into the range 4 to 9, as such it will scan through values from i to lastcolumn and accept headers(voltage,power and time) that lies within from cells(1,4) to cells(1,9) and after that the private sub voltagepowertime will be called where it creates multiple pivottables by using the columns of voltage, power and time when their headers are being detected at the first row. I will also be grateful if there are others way to express my intention here.

enter image description here

 Dim sh as Worksheet

Dim LastColumn as integer

Dim f as integer

f=4 to 9 '------>How to express f as a range of number?

For i = 1 to LastColumn

if i = f Then

if sht.Cells(1,f).Value = "Voltage" And sht.Cells(1,f).Value= "Power" and sht.Cells(1,f).Value= "Time" Then

Call voltagepowertime

Viewing all articles
Browse latest Browse all 88854

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>