Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Change InputBox Range Selection to Column Letter Selection

Hi,

I'm using the macro below that I found on the net. It works fine, but you'll
notice that the InputBox asks the user to select the range (Type: = 8). I'm
trying to modify the macro so that it asks the user for the column letter
within which the grouping labels exist (rather than range selection), and
then incorporate that information into the macro to execute the task. I can
create such an InputBox just fine (e.g., column_letter =
Application.InputBox("Which column (letter) contains the grouping variable
labels?", Type:=2), the problem is that I don't know how to integrate it into
the rest of the macro to work.

Any advice greatly appreciated.

Dim rng_grouping1 As Range
rng_regrouping As Long
rng_resized As Long
output_array2()
criteria1 As Long
criteria2 As Long
myNum As Double
number_value2 As Long

Sheets("Data").Select
Set rng_grouping1 = Application.InputBox _
("Select the spreadsheet range that contains the unit labels", Type:=8)

If rng_grouping1 Is Nothing Then Exit Sub
rng_regrouping = rng_grouping1.Value: Set rng_grouping1 = Nothing
Set rng_grouping1 = Range("Data!$FF:$FI")
If rng_grouping1 Is Nothing Then Exit Sub
rng_resized = rng_grouping1.Resize(UBound(rng_regrouping, 1), 4).Value
myNum = 0.999999
ReDim output_array2(1 To UBound(rng_regrouping, 1), 1 To 5)
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For criteria1 = 1 To UBound(rng_regrouping, 1)
If Not .exists(rng_regrouping(criteria1, 1)) Then
number_value2 = number_value2 + 1: output_array2(number_value2,
1) = rng_regrouping(criteria1, 1): .Item(rng_regrouping(criteria1, 1)) =
number_value2
End If
For criteria2 = 1 To 4
If (rng_resized(criteria1, criteria2) 0) *
(rng_resized(criteria1, criteria2) < myNum) Then
output_array2(.Item(rng_regrouping(criteria1, 1)), criteria2
+ 1) = output_array2(.Item(rng_regrouping(criteria1, 1)), criteria2 + 1) + 1
End If
Next
Next
End With

With Sheets("Units_Fit").Cells(1)
.Resize(, 5).Value = Array("Unit", "R_AVG", "M_AVG", "T_AVG", "O_AVG")
With .Offset(1).Resize(number_value2, 5)
.Value = output_array2
On Error Resume Next
.SpecialCells(4).Value = 0
End With
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Change InputBox Range Selection to Column Letter Selection

Try

Dim strCol As String
strCol = InputBox("Which column (letter) " & _
"contains the grouping variable labels?")
Set rng_grouping1 = Range("Data!" & strCol & ":" & strCol)

If this post helps click Yes
---------------
Jacob Skaria


"intoit" wrote:

Hi,

I'm using the macro below that I found on the net. It works fine, but you'll
notice that the InputBox asks the user to select the range (Type: = 8). I'm
trying to modify the macro so that it asks the user for the column letter
within which the grouping labels exist (rather than range selection), and
then incorporate that information into the macro to execute the task. I can
create such an InputBox just fine (e.g., column_letter =
Application.InputBox("Which column (letter) contains the grouping variable
labels?", Type:=2), the problem is that I don't know how to integrate it into
the rest of the macro to work.

Any advice greatly appreciated.

Dim rng_grouping1 As Range
rng_regrouping As Long
rng_resized As Long
output_array2()
criteria1 As Long
criteria2 As Long
myNum As Double
number_value2 As Long

Sheets("Data").Select
Set rng_grouping1 = Application.InputBox _
("Select the spreadsheet range that contains the unit labels", Type:=8)

If rng_grouping1 Is Nothing Then Exit Sub
rng_regrouping = rng_grouping1.Value: Set rng_grouping1 = Nothing
Set rng_grouping1 = Range("Data!$FF:$FI")
If rng_grouping1 Is Nothing Then Exit Sub
rng_resized = rng_grouping1.Resize(UBound(rng_regrouping, 1), 4).Value
myNum = 0.999999
ReDim output_array2(1 To UBound(rng_regrouping, 1), 1 To 5)
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For criteria1 = 1 To UBound(rng_regrouping, 1)
If Not .exists(rng_regrouping(criteria1, 1)) Then
number_value2 = number_value2 + 1: output_array2(number_value2,
1) = rng_regrouping(criteria1, 1): .Item(rng_regrouping(criteria1, 1)) =
number_value2
End If
For criteria2 = 1 To 4
If (rng_resized(criteria1, criteria2) 0) *
(rng_resized(criteria1, criteria2) < myNum) Then
output_array2(.Item(rng_regrouping(criteria1, 1)), criteria2
+ 1) = output_array2(.Item(rng_regrouping(criteria1, 1)), criteria2 + 1) + 1
End If
Next
Next
End With

With Sheets("Units_Fit").Cells(1)
.Resize(, 5).Value = Array("Unit", "R_AVG", "M_AVG", "T_AVG", "O_AVG")
With .Offset(1).Resize(number_value2, 5)
.Value = output_array2
On Error Resume Next
.SpecialCells(4).Value = 0
End With
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Change InputBox Range Selection to Column Letter Selection

Thanks, Jabob. Greatly appreciated.

"Jacob Skaria" wrote:

Try

Dim strCol As String
strCol = InputBox("Which column (letter) " & _
"contains the grouping variable labels?")
Set rng_grouping1 = Range("Data!" & strCol & ":" & strCol)

If this post helps click Yes
---------------
Jacob Skaria


"intoit" wrote:

Hi,

I'm using the macro below that I found on the net. It works fine, but you'll
notice that the InputBox asks the user to select the range (Type: = 8). I'm
trying to modify the macro so that it asks the user for the column letter
within which the grouping labels exist (rather than range selection), and
then incorporate that information into the macro to execute the task. I can
create such an InputBox just fine (e.g., column_letter =
Application.InputBox("Which column (letter) contains the grouping variable
labels?", Type:=2), the problem is that I don't know how to integrate it into
the rest of the macro to work.

Any advice greatly appreciated.

Dim rng_grouping1 As Range
rng_regrouping As Long
rng_resized As Long
output_array2()
criteria1 As Long
criteria2 As Long
myNum As Double
number_value2 As Long

Sheets("Data").Select
Set rng_grouping1 = Application.InputBox _
("Select the spreadsheet range that contains the unit labels", Type:=8)

If rng_grouping1 Is Nothing Then Exit Sub
rng_regrouping = rng_grouping1.Value: Set rng_grouping1 = Nothing
Set rng_grouping1 = Range("Data!$FF:$FI")
If rng_grouping1 Is Nothing Then Exit Sub
rng_resized = rng_grouping1.Resize(UBound(rng_regrouping, 1), 4).Value
myNum = 0.999999
ReDim output_array2(1 To UBound(rng_regrouping, 1), 1 To 5)
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For criteria1 = 1 To UBound(rng_regrouping, 1)
If Not .exists(rng_regrouping(criteria1, 1)) Then
number_value2 = number_value2 + 1: output_array2(number_value2,
1) = rng_regrouping(criteria1, 1): .Item(rng_regrouping(criteria1, 1)) =
number_value2
End If
For criteria2 = 1 To 4
If (rng_resized(criteria1, criteria2) 0) *
(rng_resized(criteria1, criteria2) < myNum) Then
output_array2(.Item(rng_regrouping(criteria1, 1)), criteria2
+ 1) = output_array2(.Item(rng_regrouping(criteria1, 1)), criteria2 + 1) + 1
End If
Next
Next
End With

With Sheets("Units_Fit").Cells(1)
.Resize(, 5).Value = Array("Unit", "R_AVG", "M_AVG", "T_AVG", "O_AVG")
With .Offset(1).Resize(number_value2, 5)
.Value = output_array2
On Error Resume Next
.SpecialCells(4).Value = 0
End With
End With
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo Box selection only shows bound column info after selection made. Coby Excel Programming 1 October 18th 07 02:04 AM
Range(Selection, Selection.End(xlToRight)).Select Dave Birley Excel Programming 2 June 6th 07 04:53 PM
Change from Column Selection to Cell Selection Lil Pun[_16_] Excel Programming 4 June 16th 06 10:38 PM
Other option of InputBox for range selection yogee Excel Programming 7 April 23rd 05 10:47 AM
Excel VBA - Range(Selection, Selection.End(xlDown)).Name issue. jonH Excel Programming 3 June 7th 04 09:13 PM


All times are GMT +1. The time now is 10:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"