Wednesday 15 April 2015

How to Set a Range Based on a User Selected cell reference in Excel VBA -


I am currently running a code where the user selects a cell reference (which is the column title name) and the code The dataset from that selection creates the current code by running the search command on the selected heading string. It has worked really well, but it is problematic if the title appears twice in the same row. What I want to do instead, changes the search row with the offset from the selected row, but I'm having trouble.

The original code was using the search code:

  sub-testing () dimmed as serial 1 as the string dim AR2 in the form of variant dim strows In the form of a variable late path in the form of string thumen Z. string path = ActiveWorkbook.Path ar1 = worksheet ("Sheet 1") as long as' counter dim output. Category ("C6: C222") Vala str1 = Application.InputBox ("Select data title from row 6", _ "get string", type: = 2) ar2 = category (range ("E6: IP6"). Find (str1), range ( "E6: IP6"). (Str1). End (xlDown)) for Ubound (ar1, 1) = 1 for J = 1 Output & amp; R1 (J, 1) & amp; "," & Amp; AR2 (J, 1) & amp; VbNewLine Next Open Path & amp; # 1 "# text_data.txt" output for print # 1 as output finished Close  

My new code is as follows: However, I receive a run time error ' 1004 - Application Defined or Object-Defined Error When the code goes to the line, where I set the ar2 array

  ar2 = Range (rng1.offset (0, 0), rng1.offset (216, 0)) subtest ( ) String path as string dim jade in the form of Variable Deam Path as Variable slow RNG 1 range Dim AR2 as Dim ARAI = ActiveWorkBook.Path ar1 = Worksheets ("Sheet 1") as long as 'Counter dim output. Range ("value set rng1 = Application.InputBox (" select the title of data from line 6 ", _" get string ", type: = 8) ar2 = category (rng1.offset (0, 0), rng1. Ubound (AR1, 1) Output = amp; R1 (J, 1) & amp; "," & Amp; AR2 (J, 1) for Offset (216, 0)) Jammu = 1; ; VbNewLine Next open path & output # 1 as print # 1, "stop output"  

Any help is appreciated

My solution of the problem sticks below After all, what I did was to change the size of the range that the user has chosen in the input box command and offset by the number of expected rows, which starts at the bottom of the data. Because my data is always below a certain fixed length under the selected heading.

The reference to the offsetting range came from

  sub-testing (), such asString Path = ActiveWorkbook.Path ar1 = Worksheet ("Find Friends") as Long Dim Output as String Dim Z as the Range Dim Path in the form of Variant Slow RNG as Arrayus Ar1. Range ("C6: C222") set value rng1 = Application.InputBox ("Choose the title of data from row 5", _ "select indicator", type: = 8) ar2 = rng1.Offset (1, 0). Ubound (AR1, 1) for resize (rng1.Rows.Count + 215, rng1.Column.Count) Jammu = 1 Output = Output & amp; R1 (J, 1) & amp; "," & Amp; AR2 (J, 1) & amp; VbNewLine Next Open Path & amp; Output to output # 1 as impression # 1, "Turn off Android"  

No comments:

Post a Comment