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

I need VBA help setting the output range in a script to the table value defined in a data table

$
0
0

So this is my first post here, and I hope someone can help me. I am trying to take the value of one column on a data table(CellValue column) and have it pasted "x"(URL # Column on same table) number of times. This part is fairly easy, the issue I am running into is where to paste it. I can define a single range/table to put the information but I want to have it put dynamically. I tried some Hlookup a value to define the datatable but couldn't sort it out. I have the output table value in a column on the same datatable (Table). If I change the 'Set OutRng = Range("URL_Builder[Table]").value' To define a single location like "C38" then I get the desired result, but I need it to actually paste the information to the correct table that is listed in the table column.

I need the big brain of someone here to help me figure out where I am going wrong, below is a sample of the VBA I am using, and a snapshot of the table I am working with. I sure hope this made sense.

Oh and not to mention I have to build this in a mac friendly VBA.

Sample Input Table: SampleTable

Sample VBA:

Sub CopyData()


Dim Rng As Range
Dim InputRng As Range, OutRng As Range



Set InputRng = Range("URL_Builder[[CellValue *Used for Formula*]:[Table]]")
Set OutRng = Range("URL_Builder[Table]").value

For Each Rng In InputRng.Rows
    xValue = Rng.Range("A1").Value
    xNum = Rng.Range("B1").Value
    OutRng.Resize(xNum, 1).Value = xValue
    Set OutRng = OutRng.Offset(xNum, 0)
Next
End Sub

Output should be:

SampleOutput


Viewing all articles
Browse latest Browse all 88050

Trending Articles



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