Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 385
Default Macro Needed to pull specific columns from worksheet

Is there a way to pull specific columns that will vary in number of rows to a
new worksheet ? Sometimes the columns needed will change.
Currently I have one worksheet that has 59 columns and will only need. lets
say, 15 of them. Instead of manually removing and moving in the order needed
each time I run a report, I was wondering if there is a Macro I can use ?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Macro Needed to pull specific columns from worksheet

On Apr 29, 4:17*pm, Jennifer
wrote:
Is there a way to pull specific columns that will vary in number of rows to a
new worksheet ? Sometimes the columns needed will change.
Currently I have one worksheet that has 59 columns and will only need. lets
say, 15 of them. Instead of manually removing and moving in the order needed
each time I run a report, I was wondering if there is a Macro I can use ?


Hi, you can use this but make sure you change the column ranges to
suit your spreadsheets:

Sub copycells()
ActiveWorkbook.Sheets("sheet1").Select 'source sheet
ActiveSheet.Range("a1:ce200").Select 'cell ranges
With Selection
.Copy
End With
ActiveWorkbook.Sheets("sheet2").Select 'output sheet
ActiveSheet.Range("a1").Select 'cell where the output should begin
With Selection
.PasteSpecial (xlValues) 'copies the values
.PasteSpecial (xlFormats) 'copies the formatting
End With
End Sub

Nadia
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 385
Default Macro Needed to pull specific columns from worksheet

Thank You Nadia,
Can you explain what I would indicate in the macro, which columns I would
pull into sheet2?

" wrote:

On Apr 29, 4:17 pm, Jennifer
wrote:
Is there a way to pull specific columns that will vary in number of rows to a
new worksheet ? Sometimes the columns needed will change.
Currently I have one worksheet that has 59 columns and will only need. lets
say, 15 of them. Instead of manually removing and moving in the order needed
each time I run a report, I was wondering if there is a Macro I can use ?


Hi, you can use this but make sure you change the column ranges to
suit your spreadsheets:

Sub copycells()
ActiveWorkbook.Sheets("sheet1").Select 'source sheet
ActiveSheet.Range("a1:ce200").Select 'cell ranges
With Selection
.Copy
End With
ActiveWorkbook.Sheets("sheet2").Select 'output sheet
ActiveSheet.Range("a1").Select 'cell where the output should begin
With Selection
.PasteSpecial (xlValues) 'copies the values
.PasteSpecial (xlFormats) 'copies the formatting
End With
End Sub

Nadia

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macro Needed to pull specific columns from worksheet

The following code goes into the standard code moduel. Press Alt + F11 to
open the VB editor. If you have not previously activated the code module,
use InsertModule from the menu then paste this code into the window.

Sub pullSpecificCol()

lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
REPEAT:
myCol = InputBox("Enter a Column letter. Must be Alpha character", _
"Column to Copy")
destCol = Application.InputBox("Select a cell for the column to start", _
"Column to Paste")
ActiveSheet.Range(myCol & lastRow).Copy
Worksheets("newSheet").Range(destCol)
more = MsgBox("Is there another column to copy?", vbYesNo, "CONTINUE?")
If more = vbYes Then
GoTo REPEAT:
End If
End Sub

This code will display two input boxes. The first one you type a column
letter into. The second one, use your mouse or keyboard controls to select
the destination sheet and a cell on the sheet where you want the copied
column to begin. Since you implied that the columns to be copied might not
be contiguous, this code only allows one column at a time to be copied, but
will continue until you click No when asked if you want to continue. Better
explanations of the parameters yields better solutions.

"Jennifer" wrote:

Thank You Nadia,
Can you explain what I would indicate in the macro, which columns I would
pull into sheet2?

" wrote:

On Apr 29, 4:17 pm, Jennifer
wrote:
Is there a way to pull specific columns that will vary in number of rows to a
new worksheet ? Sometimes the columns needed will change.
Currently I have one worksheet that has 59 columns and will only need. lets
say, 15 of them. Instead of manually removing and moving in the order needed
each time I run a report, I was wondering if there is a Macro I can use ?


Hi, you can use this but make sure you change the column ranges to
suit your spreadsheets:

Sub copycells()
ActiveWorkbook.Sheets("sheet1").Select 'source sheet
ActiveSheet.Range("a1:ce200").Select 'cell ranges
With Selection
.Copy
End With
ActiveWorkbook.Sheets("sheet2").Select 'output sheet
ActiveSheet.Range("a1").Select 'cell where the output should begin
With Selection
.PasteSpecial (xlValues) 'copies the values
.PasteSpecial (xlFormats) 'copies the formatting
End With
End Sub

Nadia

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macro Needed to pull specific columns from worksheet

This might work better in your circumstance. It measures each column length
rather than using column A length for all all copy ranges.

Sub pullSpecificCol()
Dim destCol As Range

REPEAT:
myCol = InputBox("Enter a Column letter. Must be Alpha character", _
"Column to Copy")
lastRow = ActiveSheet.Cells(Rows.Count, myCol).End(xlUp).Row
Set destCol = Application.InputBox("Select a cell for the column to
start", _
"Column to Paste", Type:=8)
ActiveSheet.Range(myCol & 1 & ":" & myCol & lastRow).Copy destCol
CutCopyMode = False
more = MsgBox("Is there another column to copy?", vbYesNo, "CONTINUE?")
If more = vbYes Then
GoTo REPEAT:
End If
End Sub

"Jennifer" wrote:

Thank You Nadia,
Can you explain what I would indicate in the macro, which columns I would
pull into sheet2?

" wrote:

On Apr 29, 4:17 pm, Jennifer
wrote:
Is there a way to pull specific columns that will vary in number of rows to a
new worksheet ? Sometimes the columns needed will change.
Currently I have one worksheet that has 59 columns and will only need. lets
say, 15 of them. Instead of manually removing and moving in the order needed
each time I run a report, I was wondering if there is a Macro I can use ?


Hi, you can use this but make sure you change the column ranges to
suit your spreadsheets:

Sub copycells()
ActiveWorkbook.Sheets("sheet1").Select 'source sheet
ActiveSheet.Range("a1:ce200").Select 'cell ranges
With Selection
.Copy
End With
ActiveWorkbook.Sheets("sheet2").Select 'output sheet
ActiveSheet.Range("a1").Select 'cell where the output should begin
With Selection
.PasteSpecial (xlValues) 'copies the values
.PasteSpecial (xlFormats) 'copies the formatting
End With
End Sub

Nadia



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 385
Default Macro Needed to pull specific columns from worksheet

Thank you for the code, I am receiving an error on either code at the pint
where it indicates:
Worksheets("newSheet").Range (destCol)
With Nadias posting it did pull over one column, just trying to determining
how I list each column range in her macro ? Is it a separate line of code or
all in line of code ?

Example: Where it indicates ActiveSheet.Range("a1:ce200").Select 'cell
ranges , how would I list each column ?

Sub copycells()
ActiveWorkbook.Sheets("sheet1").Select 'source sheet
ActiveSheet.Range("a1:ce200").Select 'cell ranges
With Selection
..Copy
End With
ActiveWorkbook.Sheets("sheet2").Select 'output sheet
ActiveSheet.Range("a1").Select 'cell where the output should begin
With Selection
..PasteSpecial (xlValues) 'copies the values
..PasteSpecial (xlFormats) 'copies the formatting
End With
End Sub


"JLGWhiz" wrote:

This might work better in your circumstance. It measures each column length
rather than using column A length for all all copy ranges.

Sub pullSpecificCol()
Dim destCol As Range

REPEAT:
myCol = InputBox("Enter a Column letter. Must be Alpha character", _
"Column to Copy")
lastRow = ActiveSheet.Cells(Rows.Count, myCol).End(xlUp).Row
Set destCol = Application.InputBox("Select a cell for the column to
start", _
"Column to Paste", Type:=8)
ActiveSheet.Range(myCol & 1 & ":" & myCol & lastRow).Copy destCol
CutCopyMode = False
more = MsgBox("Is there another column to copy?", vbYesNo, "CONTINUE?")
If more = vbYes Then
GoTo REPEAT:
End If
End Sub

"Jennifer" wrote:

Thank You Nadia,
Can you explain what I would indicate in the macro, which columns I would
pull into sheet2?

" wrote:

On Apr 29, 4:17 pm, Jennifer
wrote:
Is there a way to pull specific columns that will vary in number of rows to a
new worksheet ? Sometimes the columns needed will change.
Currently I have one worksheet that has 59 columns and will only need. lets
say, 15 of them. Instead of manually removing and moving in the order needed
each time I run a report, I was wondering if there is a Macro I can use ?

Hi, you can use this but make sure you change the column ranges to
suit your spreadsheets:

Sub copycells()
ActiveWorkbook.Sheets("sheet1").Select 'source sheet
ActiveSheet.Range("a1:ce200").Select 'cell ranges
With Selection
.Copy
End With
ActiveWorkbook.Sheets("sheet2").Select 'output sheet
ActiveSheet.Range("a1").Select 'cell where the output should begin
With Selection
.PasteSpecial (xlValues) 'copies the values
.PasteSpecial (xlFormats) 'copies the formatting
End With
End Sub

Nadia

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 385
Default Macro Needed to pull specific columns from worksheet

Any ideas on this one ?

"Jennifer" wrote:

Thank you for the code, I am receiving an error on either code at the pint
where it indicates:
Worksheets("newSheet").Range (destCol)
With Nadias posting it did pull over one column, just trying to determining
how I list each column range in her macro ? Is it a separate line of code or
all in line of code ?

Example: Where it indicates ActiveSheet.Range("a1:ce200").Select 'cell
ranges , how would I list each column ?

Sub copycells()
ActiveWorkbook.Sheets("sheet1").Select 'source sheet
ActiveSheet.Range("a1:ce200").Select 'cell ranges
With Selection
.Copy
End With
ActiveWorkbook.Sheets("sheet2").Select 'output sheet
ActiveSheet.Range("a1").Select 'cell where the output should begin
With Selection
.PasteSpecial (xlValues) 'copies the values
.PasteSpecial (xlFormats) 'copies the formatting
End With
End Sub


"JLGWhiz" wrote:

This might work better in your circumstance. It measures each column length
rather than using column A length for all all copy ranges.

Sub pullSpecificCol()
Dim destCol As Range

REPEAT:
myCol = InputBox("Enter a Column letter. Must be Alpha character", _
"Column to Copy")
lastRow = ActiveSheet.Cells(Rows.Count, myCol).End(xlUp).Row
Set destCol = Application.InputBox("Select a cell for the column to
start", _
"Column to Paste", Type:=8)
ActiveSheet.Range(myCol & 1 & ":" & myCol & lastRow).Copy destCol
CutCopyMode = False
more = MsgBox("Is there another column to copy?", vbYesNo, "CONTINUE?")
If more = vbYes Then
GoTo REPEAT:
End If
End Sub

"Jennifer" wrote:

Thank You Nadia,
Can you explain what I would indicate in the macro, which columns I would
pull into sheet2?

" wrote:

On Apr 29, 4:17 pm, Jennifer
wrote:
Is there a way to pull specific columns that will vary in number of rows to a
new worksheet ? Sometimes the columns needed will change.
Currently I have one worksheet that has 59 columns and will only need. lets
say, 15 of them. Instead of manually removing and moving in the order needed
each time I run a report, I was wondering if there is a Macro I can use ?

Hi, you can use this but make sure you change the column ranges to
suit your spreadsheets:

Sub copycells()
ActiveWorkbook.Sheets("sheet1").Select 'source sheet
ActiveSheet.Range("a1:ce200").Select 'cell ranges
With Selection
.Copy
End With
ActiveWorkbook.Sheets("sheet2").Select 'output sheet
ActiveSheet.Range("a1").Select 'cell where the output should begin
With Selection
.PasteSpecial (xlValues) 'copies the values
.PasteSpecial (xlFormats) 'copies the formatting
End With
End Sub

Nadia

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
Macro to pull in specific data into multiple worksheets in a workb murkaboris Excel Discussion (Misc queries) 0 April 14th 09 06:25 PM
Macro needed to pull data from one worksheet and enter it in anoth bigproblem Excel Discussion (Misc queries) 2 November 18th 08 02:14 PM
How do I pull a specific name based on a specific value from mult. rpctoo Excel Worksheet Functions 1 August 10th 07 04:12 PM
Worksheet-specific event handling needed syswizard Excel Programming 4 March 10th 07 08:53 PM
Can a worksheet pull from a specific cell value in a separate wrks reloanpro Excel Worksheet Functions 4 June 27th 05 10:03 PM


All times are GMT +1. The time now is 06:33 PM.

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"