Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default InputBox for column letter problem

The second InputBox is to get the column letter of the last column to include in the code as the range to transfer a long column/s into several shorter column/s to the next sheet.

I want to be able to change nCols in this line to the column of my choice.

wks1.Range("A" & i & ":nCols" & i + nnCols).Copy wks2.Cells(1, j)...

I can hard code it to C, D or whatever and it works fine.

Thanks.
Howard

Option Explicit

Sub AcolumToNcolumns()

Dim wks1 As Worksheet, wks2 As Worksheet
Dim iColumn As Integer
Dim lLast As Long
Dim i As Long, j As Integer, y As Integer
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

nnCols = nRows - 1

Set wks1 = Worksheets("One Column")
Set wks2 = Worksheets("N Columns")

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

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

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

If lLast < nRows Then
MsgBox "Less than nnCols rows", vbOKOnly
Exit Sub
End If

For i = 1 To lLast Step nRows

wks1.Range("A" & 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("A" & 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

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default InputBox for column letter problem

Hi Howard,

Am Tue, 21 Jan 2014 19:32:52 -0800 (PST) schrieb L. Howard:

wks1.Range("A" & i & ":nCols" & i + nnCols).Copy wks2.Cells(1, j)


change the line above to:
wks1.Range("A" & i & ":" & nCols & i + nnCols).Copy wks2.Cells(1, j)


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default InputBox for column letter problem

On Wednesday, January 22, 2014 12:19:46 AM UTC-8, Claus Busch wrote:
Hi Howard,



Am Tue, 21 Jan 2014 19:32:52 -0800 (PST) schrieb L. Howard:



wks1.Range("A" & i & ":nCols" & i + nnCols).Copy wks2.Cells(1, j)




change the line above to:

wks1.Range("A" & i & ":" & nCols & i + nnCols).Copy wks2.Cells(1, j)





Regards

Claus B.



Right on!! I was thinking the problem was with the InputBox not the syntax of the code line.

Works great!

Thanks Claus.

Regards,
Howard
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
Change InputBox Range Selection to Column Letter Selection intoit Excel Programming 2 July 21st 09 07:58 AM
How do I turn excel columns from column number to column letter? column Setting up and Configuration of Excel 1 April 29th 08 10:15 AM
How to replace column letter in refferences with a function using the old column letter? Dmitry Kopnichev Links and Linking in Excel 6 October 13th 05 09:09 AM
How to replace column letter in refferences with a function using the old column letter? Dmitry Kopnichev Excel Worksheet Functions 6 October 13th 05 09:09 AM
column header changed from letter to number, how return to letter Ron Excel Discussion (Misc queries) 2 May 9th 05 08:34 PM


All times are GMT +1. The time now is 10:52 AM.

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"