Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Macro question

Hello all,

Could anyone tell me about using Macro /VBA as below

1) How to copy several whole columns from one sheet to another sheet within
the same Excel file?
2) How to detect the column and fill the number into another column?
e.g. ColumnA2 to A99 contains data, then it can fill the number from
1,2,3,4,5.....................,97,98 into the column B2 to B99
automatically?

Thank you for your help first.

TLee



  #2   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Macro question

here are three examples for you:

1) copy a column on the same sheet
Range("J:J").Value = Range("E:E").Value

2)Copy a column to another sheet
Worksheets("sheet2").Range("J:J").Value = Range("E:E").Value

3) copy a range to another sheet
Dim source As Range
Set source = Worksheets("Sheet1").Range("E6:G20")
With source
Worksheets("sheet3").Range("J2").Resize(.Rows.Coun t,
..Columns.Count).Value = .Value
End With

"tlee" wrote in message
...
Hello all,

Could anyone tell me about using Macro /VBA as below

1) How to copy several whole columns from one sheet to another sheet
within the same Excel file?
2) How to detect the column and fill the number into another column?
e.g. ColumnA2 to A99 contains data, then it can fill the number from
1,2,3,4,5.....................,97,98 into the column B2 to B99
automatically?

Thank you for your help first.

TLee



  #3   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Macro question

TLee,

1)

Worksheets("Sheet1").Range("A:C").Copy Worksheets("Sheet2").Range("H:J")

2)

With Worksheets("Sheet1").Range("A2", Cells(Rows.Count, 1).End(xlUp)).Offset(0, 1)
.Formula = "=ROW()-1"
.Value = .Value
End With


HTH,
Bernie
MS Excel MVP


"tlee" wrote in message ...
Hello all,

Could anyone tell me about using Macro /VBA as below

1) How to copy several whole columns from one sheet to another sheet within the same Excel file?
2) How to detect the column and fill the number into another column?
e.g. ColumnA2 to A99 contains data, then it can fill the number from
1,2,3,4,5.....................,97,98 into the column B2 to B99 automatically?

Thank you for your help first.

TLee





  #4   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Macro question

Patrick,

?.Value = ?.Value is essentially paste special / values, not necessarily "copy"

Bernie


"Patrick Molloy" wrote in message
...
here are three examples for you:

1) copy a column on the same sheet
Range("J:J").Value = Range("E:E").Value

2)Copy a column to another sheet
Worksheets("sheet2").Range("J:J").Value = Range("E:E").Value

3) copy a range to another sheet
Dim source As Range
Set source = Worksheets("Sheet1").Range("E6:G20")
With source
Worksheets("sheet3").Range("J2").Resize(.Rows.Coun t, .Columns.Count).Value = .Value
End With

"tlee" wrote in message ...
Hello all,

Could anyone tell me about using Macro /VBA as below

1) How to copy several whole columns from one sheet to another sheet within the same Excel file?
2) How to detect the column and fill the number into another column?
e.g. ColumnA2 to A99 contains data, then it can fill the number from
1,2,3,4,5.....................,97,98 into the column B2 to B99 automatically?

Thank you for your help first.

TLee





  #5   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Macro question

Try these:

Pastes columns c thru f of sheet one to columns a
thru d of sheet two.

Sub cpyExpl()
Sheets(1).Columns("C:F").Copy Sheets(2).Range("A1")
End Sub

move data using For Each loop.

Sub fe()
For Each c In Range("A2:A99")
If c.Value < "" Then
c.Offset(0, 1) = c.Value
End If
Next
End Sub



"tlee" wrote in message
...
Hello all,

Could anyone tell me about using Macro /VBA as below

1) How to copy several whole columns from one sheet to another sheet
within the same Excel file?
2) How to detect the column and fill the number into another column?
e.g. ColumnA2 to A99 contains data, then it can fill the number from
1,2,3,4,5.....................,97,98 into the column B2 to B99
automatically?

Thank you for your help first.

TLee







  #6   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Macro question

Hi all,

Thank you all of yours help.

Bernie,
As for the point 2, how can I specified to detect the Column A only, which
contains data, and then write the sequence number (e.g. 1.........9999) into
the specified column G (start from G2) automatically?

Because, I found that all another columns data are also changed to the same
value as column G.

I change your code from "A2" to "G2"
With Worksheets("Sheet1").Range("G2", Cells(Rows.Count,
1).End(xlUp)).Offset(0, 1)
.Formula = "=ROW()-1"
.Value = .Value
End With

Thanks
Tlee


TLee,

1)

Worksheets("Sheet1").Range("A:C").Copy Worksheets("Sheet2").Range("H:J")

2)

With Worksheets("Sheet1").Range("A2", Cells(Rows.Count,
1).End(xlUp)).Offset(0, 1)
.Formula = "=ROW()-1"
.Value = .Value
End With


HTH,
Bernie
MS Excel MVP


"tlee" wrote in message
...
Hello all,

Could anyone tell me about using Macro /VBA as below

1) How to copy several whole columns from one sheet to another sheet
within the same Excel file?
2) How to detect the column and fill the number into another column?
e.g. ColumnA2 to A99 contains data, then it can fill the number from
1,2,3,4,5.....................,97,98 into the column B2 to B99
automatically?

Thank you for your help first.

TLee





  #7   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Macro question

You also need to change the offset:

With Worksheets("Sheet1").Range("G2", Cells(Rows.Count,
1).End(xlUp)).Offset(0, 6)
.Formula = "=ROW()-1"
.Value = .Value
End With

HTH,
Bernie
MS Excel <VP

"tlee" wrote in message
...
Hi all,

Thank you all of yours help.

Bernie,
As for the point 2, how can I specified to detect the Column A only,
which contains data, and then write the sequence number (e.g.
1.........9999) into the specified column G (start from G2)
automatically?

Because, I found that all another columns data are also changed to the
same value as column G.

I change your code from "A2" to "G2"
With Worksheets("Sheet1").Range("G2", Cells(Rows.Count,
1).End(xlUp)).Offset(0, 1)
.Formula = "=ROW()-1"
.Value = .Value
End With

Thanks
Tlee


TLee,

1)

Worksheets("Sheet1").Range("A:C").Copy Worksheets("Sheet2").Range("H:J")

2)

With Worksheets("Sheet1").Range("A2", Cells(Rows.Count,
1).End(xlUp)).Offset(0, 1)
.Formula = "=ROW()-1"
.Value = .Value
End With


HTH,
Bernie
MS Excel MVP


"tlee" wrote in message
...
Hello all,

Could anyone tell me about using Macro /VBA as below

1) How to copy several whole columns from one sheet to another sheet
within the same Excel file?
2) How to detect the column and fill the number into another column?
e.g. ColumnA2 to A99 contains data, then it can fill the number from
1,2,3,4,5.....................,97,98 into the column B2 to B99
automatically?

Thank you for your help first.

TLee






  #8   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Macro question

Bernie, JLGWhiz, Patrick,

Thanks alot for your helps

TLee


You also need to change the offset:

With Worksheets("Sheet1").Range("G2", Cells(Rows.Count,
1).End(xlUp)).Offset(0, 6)
.Formula = "=ROW()-1"
.Value = .Value
End With

HTH,
Bernie
MS Excel <VP

"tlee" wrote in message
...
Hi all,

Thank you all of yours help.

Bernie,
As for the point 2, how can I specified to detect the Column A only,
which contains data, and then write the sequence number (e.g.
1.........9999) into the specified column G (start from G2)
automatically?

Because, I found that all another columns data are also changed to the
same value as column G.

I change your code from "A2" to "G2"
With Worksheets("Sheet1").Range("G2", Cells(Rows.Count,
1).End(xlUp)).Offset(0, 1)
.Formula = "=ROW()-1"
.Value = .Value
End With

Thanks
Tlee


TLee,

1)

Worksheets("Sheet1").Range("A:C").Copy Worksheets("Sheet2").Range("H:J")

2)

With Worksheets("Sheet1").Range("A2", Cells(Rows.Count,
1).End(xlUp)).Offset(0, 1)
.Formula = "=ROW()-1"
.Value = .Value
End With


HTH,
Bernie
MS Excel MVP


"tlee" wrote in message
...
Hello all,

Could anyone tell me about using Macro /VBA as below

1) How to copy several whole columns from one sheet to another sheet
within the same Excel file?
2) How to detect the column and fill the number into another column?
e.g. ColumnA2 to A99 contains data, then it can fill the number from
1,2,3,4,5.....................,97,98 into the column B2 to B99
automatically?

Thank you for your help first.

TLee








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 question Tina Excel Worksheet Functions 2 March 15th 10 03:23 AM
Excel 2007 Macro/VB Question DDE Question MadDog22 Excel Worksheet Functions 1 March 10th 10 01:47 AM
Macro Question carl Excel Worksheet Functions 2 May 15th 07 07:23 PM
Macro Help / Question Ed[_14_] Excel Programming 3 January 9th 04 12:46 AM
Macro Question dizzydean Excel Programming 2 December 23rd 03 06:15 PM


All times are GMT +1. The time now is 12:39 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"