Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Copy a range instead of just one row but with condition

Hi Everyone
The small macro below copies the information from row 20 on to an order form
sheet.
I need to have it check from row 20 to row 36 and copy it if column B starts
with a number.
Your help is always appreciated. Thank you
Sub Parts_Order()
With Sheets("Parts Order Form")
'QTY
lLastRow = .Cells(.Rows.Count, "a").End(xlUp).Row
.Cells(lLastRow + 1, "a").Value = _
Sheets("Invoice").Range("A20").Value
'Part Number
lLastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
.Cells(lLastRow + 1, "B").Value = _
Sheets("Invoice").Range("b20").Value
End With
End Sub
Sub Parts_Order()
'Invoice Number
lLastRow = .Cells(.Rows.Count, "d").End(xlUp).Row
.Cells(lLastRow + 1, "d").Value = _
Sheets("Invoice").Range("K2").Value
'QTY
lLastRow = .Cells(.Rows.Count, "a").End(xlUp).Row
.Cells(lLastRow + 1, "a").Value = _
Sheets("Invoice").Range("A20").Value
'Part Number
lLastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
.Cells(lLastRow + 1, "B").Value = _
Sheets("Invoice").Range("b20").Value
End With
End Sub
Regards
Cimjet

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy a range instead of just one row but with condition

Hi Cimjet,

Am Mon, 20 Jun 2011 11:25:41 -0400 schrieb Cimjet:

The small macro below copies the information from row 20 on to an order form
sheet.
I need to have it check from row 20 to row 36 and copy it if column B starts
with a number.


try this:
Sub Parts_Order()
Dim FRow As Long
Dim i As Integer
Dim Pos1 As String

With Sheets("Parts Order Form")
For i = 20 To 36
FRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
Pos1 = Left(Sheets("Invoice").Cells(i, 2), 1)
If IsNumeric(Pos1) Then
Sheets("Invoice").Rows(i).Copy _
Destination:=.Range("A" & FRow)
End If
Next
End With

End Sub


Regards
Claus Busch
--
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: 157
Default Copy a range instead of just one row but with condition

Hi Claus
Thank you very much. it works.
Can this be modified to copy the value only, now it's pasting the formulas and
one row "B" is a Data Validation box.
Regards
Cimjet

"Claus Busch" wrote in message
...
Hi Cimjet,

Am Mon, 20 Jun 2011 11:25:41 -0400 schrieb Cimjet:

The small macro below copies the information from row 20 on to an order form
sheet.
I need to have it check from row 20 to row 36 and copy it if column B starts
with a number.


try this:
Sub Parts_Order()
Dim FRow As Long
Dim i As Integer
Dim Pos1 As String

With Sheets("Parts Order Form")
For i = 20 To 36
FRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
Pos1 = Left(Sheets("Invoice").Cells(i, 2), 1)
If IsNumeric(Pos1) Then
Sheets("Invoice").Rows(i).Copy _
Destination:=.Range("A" & FRow)
End If
Next
End With

End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy a range instead of just one row but with condition

Hi Cimjet,

Am Mon, 20 Jun 2011 12:27:51 -0400 schrieb Cimjet:

Can this be modified to copy the value only, now it's pasting the formulas and
one row "B" is a Data Validation box.


then change the if block to:
If IsNumeric(Pos1) Then
Sheets("Invoice").Rows(i).Copy
.Range("A" & FRow).PasteSpecial xlPasteValues
End If


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Copy a range instead of just one row but with condition

Hi Claus
That did it.
Thank you very much
Best regards
Cimjet

"Claus Busch" wrote in message
...
Hi Cimjet,

Am Mon, 20 Jun 2011 12:27:51 -0400 schrieb Cimjet:

Can this be modified to copy the value only, now it's pasting the formulas
and
one row "B" is a Data Validation box.


then change the if block to:
If IsNumeric(Pos1) Then
Sheets("Invoice").Rows(i).Copy
.Range("A" & FRow).PasteSpecial xlPasteValues
End If


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Copy a range instead of just one row but with condition

Hi Claus
I was to fast in my request yesterday, I was missing information.
Instead of the full Row, I need only column A,B and D.
I tried to change it but without success.
Your help would be very much appreciated.
Cimjet
"Claus Busch" wrote in message
...
Hi Cimjet,

Am Mon, 20 Jun 2011 12:27:51 -0400 schrieb Cimjet:

Can this be modified to copy the value only, now it's pasting the formulas
and
one row "B" is a Data Validation box.


then change the if block to:
If IsNumeric(Pos1) Then
Sheets("Invoice").Rows(i).Copy
.Range("A" & FRow).PasteSpecial xlPasteValues
End If


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy a range instead of just one row but with condition

Hi,

Am Tue, 21 Jun 2011 08:16:48 -0400 schrieb Cimjet:

Instead of the full Row, I need only column A,B and D.
I tried to change it but without success.


try this:
Sub Parts_Order()
Dim FRow As Long
Dim i As Integer
Dim Pos1 As String
Dim myRange As Range

With Sheets("Parts Order Form")
For i = 20 To 36
FRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
Pos1 = Left(Sheets("Invoice").Cells(i, 2), 1)
If IsNumeric(Pos1) Then
Set myRange = Application.Union(Sheets("Invoice"). _
Range("A" & i & ":B" & i), Sheets("Invoice") _
.Range("D" & i))
myRange.Copy
.Range("A" & FRow).PasteSpecial xlPasteValues
End If
Next
End With

End Sub



Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy a range instead of just one row but with condition

Hi Cimjet,

faster version:
Sub Parts_Order2()
Dim FRow As Long
Dim i As Integer
Dim Pos1 As String
Dim myRange As Range

Application.ScreenUpdating = False
With Sheets("Parts Order Form")
For i = 20 To 36
FRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
Pos1 = Left(Sheets("Invoice").Cells(i, 2), 1)
If IsNumeric(Pos1) Then
.Cells(FRow, 1) = Sheets("Invoice").Cells(i, 1)
.Cells(FRow, 2) = Sheets("Invoice").Cells(i, 2)
.Cells(FRow, 3) = Sheets("Invoice").Cells(i, 4)
End If
Next
End With
Application.ScreenUpdating = True
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Copy a range instead of just one row but with condition

Hi Claus
Thank you very much, it works perfectly.
Have a great day
Cimjet
"Claus Busch" wrote in message
...
Hi Cimjet,

faster version:
Sub Parts_Order2()
Dim FRow As Long
Dim i As Integer
Dim Pos1 As String
Dim myRange As Range

Application.ScreenUpdating = False
With Sheets("Parts Order Form")
For i = 20 To 36
FRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
Pos1 = Left(Sheets("Invoice").Cells(i, 2), 1)
If IsNumeric(Pos1) Then
.Cells(FRow, 1) = Sheets("Invoice").Cells(i, 1)
.Cells(FRow, 2) = Sheets("Invoice").Cells(i, 2)
.Cells(FRow, 3) = Sheets("Invoice").Cells(i, 4)
End If
Next
End With
Application.ScreenUpdating = True
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


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
Condition based copy/paste of range [email protected] Excel Programming 1 April 28th 07 11:30 PM
Condition based copy/paste of range [email protected] Excel Programming 1 April 27th 07 12:44 PM
Condition based copy/paste of range [email protected] Excel Programming 0 April 27th 07 05:48 AM
Copy range based on condition Sotomayor Excel Programming 1 September 10th 06 01:11 AM
Create/copy combo boxes in one range if condition is met in a different range LB[_4_] Excel Programming 4 September 30th 05 12:21 AM


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