Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Expand column to copy

Hi all,

Couls someone please advise me hot to amend this code so as to cop
column B and C to column B and C on sheet1. It currently only copie
and pastes one column.

Cheers all!!!!!

Private Sub CommandButton1_Click()
CopyData Range("C10:C18"), "BASE MACHINE"
CopyData Range("C34:C103"), "CONTROL INCLUSIONS - UNIT 1"
CopyData Range("C108:C117"), "FEEDER INCLUSIONS - UNIT 1"
CopyData Range("C122:C179"), "FOLDING UNIT INCLUSIONS - UNIT 1"
CopyData Range("C191:C227"), "CONTROL INCLUSIONS - UNIT 2, 78cm"
CopyData Range("C232:C286"), "FOLDING UNIT INCLUSIONS - UNIT 2, 78cm"
CopyData Range("C298:C331"), "CONTROL INCLUSIONS - UNIT 2, 68cm"
CopyData Range("C336:C390"), "FOLDING UNIT INCLUSIONS - UNIT 2, 68cm"
CopyData Range("C471:C486"), "CONTROL INCLUSIONS - UNIT 3, 56cm"
CopyData Range("C425:C470"), "FOLDING UNIT INCLUSIONS - UNIT 3, 56cm"
End Sub
Private Sub CopyData(rngC As Range, Target As String)
Dim rng As Range, cell As Range
Dim rng1 As Range, rng2 As Range
Dim rng3 As Range
Dim nrow As Long, rw As Long
Dim Sh As Worksheet
nrow = Application.CountIf(rngC, "0")
If nrow = 0 Then Exit Sub
Set Sh = Worksheets("sheet1")
Set rng = Sh.Columns(1).Find(What:=Target, _
After:=Sh.Range("A1"), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If rng Is Nothing Then
MsgBox Target & " Not found"
Exit Sub
End If
Set rng3 = rng
Worksheets("sheet1").Unprotect Password:="jenjen1"
rng.Offset(1, 0).ClearContents
If Application.CountA(rng3) 2 Then
Else
Set rng3 = rng.Offset(2, 0)
End If
rw = rng3.Row
rng3.Resize(nrow * 2, 1).EntireRow.Insert
For Each cell In rngC
If Not IsEmpty(cell) Then
If IsNumeric(cell) Then
If cell 0 Then
Cells(cell.Row, 1).Resize(1, 2).Copy _
Destination:=Sh.Cells(rw, 1)
rw = rw + 2
End If
End If
End If
Next
Worksheets("sheet1").Protect Password:="jenjen1"
End Su

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Expand column to copy

Cells(cell.Row, 1).Resize(1, 2).Copy _
Destination:=Sh.Cells(rw, 1)

clearly copies A and B to A and B

so I am not sure why you say it copies only one column. If you want B and C

Cells(cell.Row, 2).Resize(1, 2).Copy _
Destination:=Sh.Cells(rw, 2)


--
Regards,
Tom Ogilvy

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

Couls someone please advise me hot to amend this code so as to copy
column B and C to column B and C on sheet1. It currently only copies
and pastes one column.

Cheers all!!!!!

Private Sub CommandButton1_Click()
CopyData Range("C10:C18"), "BASE MACHINE"
CopyData Range("C34:C103"), "CONTROL INCLUSIONS - UNIT 1"
CopyData Range("C108:C117"), "FEEDER INCLUSIONS - UNIT 1"
CopyData Range("C122:C179"), "FOLDING UNIT INCLUSIONS - UNIT 1"
CopyData Range("C191:C227"), "CONTROL INCLUSIONS - UNIT 2, 78cm"
CopyData Range("C232:C286"), "FOLDING UNIT INCLUSIONS - UNIT 2, 78cm"
CopyData Range("C298:C331"), "CONTROL INCLUSIONS - UNIT 2, 68cm"
CopyData Range("C336:C390"), "FOLDING UNIT INCLUSIONS - UNIT 2, 68cm"
CopyData Range("C471:C486"), "CONTROL INCLUSIONS - UNIT 3, 56cm"
CopyData Range("C425:C470"), "FOLDING UNIT INCLUSIONS - UNIT 3, 56cm"
End Sub
Private Sub CopyData(rngC As Range, Target As String)
Dim rng As Range, cell As Range
Dim rng1 As Range, rng2 As Range
Dim rng3 As Range
Dim nrow As Long, rw As Long
Dim Sh As Worksheet
nrow = Application.CountIf(rngC, "0")
If nrow = 0 Then Exit Sub
Set Sh = Worksheets("sheet1")
Set rng = Sh.Columns(1).Find(What:=Target, _
After:=Sh.Range("A1"), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If rng Is Nothing Then
MsgBox Target & " Not found"
Exit Sub
End If
Set rng3 = rng
Worksheets("sheet1").Unprotect Password:="jenjen1"
rng.Offset(1, 0).ClearContents
If Application.CountA(rng3) 2 Then
Else
Set rng3 = rng.Offset(2, 0)
End If
rw = rng3.Row
rng3.Resize(nrow * 2, 1).EntireRow.Insert
For Each cell In rngC
If Not IsEmpty(cell) Then
If IsNumeric(cell) Then
If cell 0 Then
Cells(cell.Row, 1).Resize(1, 2).Copy _
Destination:=Sh.Cells(rw, 1)
rw = rw + 2
End If
End If
End If
Next
Worksheets("sheet1").Protect Password:="jenjen1"
End Sub


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Expand column to copy

Tom,

I apologise for the confusion. Could you advise how to copy the cel
values rather than the formulas?

Cheers!

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Expand column to copy

Tom,

All is resolved.

Thank you!!!

--
Message posted from http://www.ExcelForum.com

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
How to copy a cell and horizontally expand the paste along header al7riv Excel Discussion (Misc queries) 7 April 10th 12 02:01 PM
Can I expand a cell without expanding the whole column in Excel? Monica Excel Worksheet Functions 1 July 24th 09 11:42 PM
How do I expand my excel worksheet past column IV Roy Setting up and Configuration of Excel 2 December 19th 07 12:04 PM
Expand only one cell in a column brocklang Excel Discussion (Misc queries) 1 August 29th 06 09:29 PM
how do I expand a cell without expanding column ashaback Excel Worksheet Functions 1 March 23rd 06 05:25 PM


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