LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Combine three InputBoxes into one?

Using three inputboxes this code works okay. Takes a column from sheet 1 and makes shorter columns on sheet 2

I would like to do two things.

1. Combine all three entries to a single inputbox, say comma delimited.
2. When referring to the source and destination columns use a letter. (Code below uses a letter for Source and a "number - 1" for Destination column.)

Then split the inputboxes entries to the variables.

Where an inputbox entry would look like 10,D,F would be:

10 rows at a time from column D on source sheet column, post to destination sheet starting at column F and to the right. If last column is not a full 10 rows that is ok.

Thanks.
Howard

Sub ColumnToColumns()

Dim wks1 As Worksheet, wks2 As Worksheet
Dim iColumn As Integer
Dim lLast As Long
Dim i As Long, j As Long ', y As Long
Dim DestCol As String
Dim nRows As String
Dim nnCols As String
Dim nCols As String

nRows = InputBox("Colum No. of Rows.", "Enter value")
If nRows = vbNullString Then Exit Sub

nCols = InputBox("Colum A to Column ?", "Enter Column Letter")
If nCols = vbNullString Then Exit Sub

DestCol = Application.InputBox("Destination Colum 1 = A, 26 = Z ?", "Enter Destination Column number", , , , , , 1)
If DestCol = vbNullString Then Exit Sub

nnCols = nRows - 1

Application.ScreenUpdating = False

Set wks1 = Worksheets("Sheet2") '/ Rename to your workbook
Set wks2 = Worksheets("Sheet3") '/ Rename to your workbook

lLast = wks1.Cells(wks1.Rows.Count, 1).End(xlUp).Row

j = wks2.Cells(1, wks2.Columns.Count).End(xlToLeft).Column + (DestCol - 1)

For iColumn = 1 To nRows
lLast = Application.Max(lLast, wks1.Cells(wks1.Rows.Count, _
iColumn).End(xlUp).Row)
Next iColumn

For i = 1 To lLast Step nRows
wks1.Range(nCols & i & ":" & nCols & i + nnCols).Copy wks2.Cells(1, j)
j = wks2.Cells(1, wks2.Columns.Count).End(xlToLeft).Column + 1

' To cut data to sheet 2
'wks1.Range(nCols & i & ":" & nCols & i + nnCols).Cut wks2.Cells(1, j)
'j = wks2.Cells(1, wks2.Columns.Count).End(xlToLeft).Column + 1

Next

wks2.Activate
Columns("A:Z").HorizontalAlignment = xlCenter
Application.Columns("A:Z").AutoFit

wks1.Activate
Set wks1 = Nothing
Set wks2 = Nothing

Application.ScreenUpdating = True
End Sub
 
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
InputBoxes & Ranges Faraz A. Qureshi Excel Programming 5 September 13th 09 03:10 AM
Ranges & Inputboxes? Faraz A. Qureshi Excel Programming 4 September 11th 09 09:33 AM
userform and inputboxes pswanie Excel Programming 1 January 3rd 08 04:09 PM
InputBoxes Sean Excel Programming 2 July 19th 06 06:09 PM
InputBoxes Exceptions ianripping[_42_] Excel Programming 3 April 8th 04 09:34 PM


All times are GMT +1. The time now is 01:31 AM.

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

About Us

"It's about Microsoft Excel"