Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Strange cut and paste result between worksheets

Another situation where I'm cutting and pasting between different worksheets.
The problem is that for some reason, the data copied FROM the source sheet
(sheet1) becomes values only on the paste sheet (sh) AND the source sheet.
Doesn't make any sense to me. I've checked all my other procedures and
narrowed it down to this one.
Any ideas?

--------------------------------------------
Public Sub SyncAESheet()
Dim ArtCol As Long
Dim i As Long
Dim FirstRow As Variant
Dim LastRow As Variant
Dim CellVal As Long
Dim RowNum As Long
Dim ArtNum As Long
Dim LookUpRng As Range
Dim sh As Worksheet

Application.ScreenUpdating = False

Set sh = ActiveSheet
ArtCol = 1 'means col A

With sh ' This loop finds the first and last rows
i = 1
Do Until FirstRow < Empty
If IsNumeric(.Cells(i, "A")) Then
If .Cells(i, "A").Value 0 Then
FirstRow = i
End If
ElseIf i 50 Then FirstRow = 1
Else: FirstRow = Empty
End If
i = i + 1
Loop
i = FirstRow
Do Until LastRow < Empty
If .Cells(i + 1, "A").Value = "" Then
LastRow = i
ElseIf .Cells(i + 2, "A").Value = "" Then
LastRow = i + 1
Else: LastRow = Empty
i = i + 1
End If
Loop
End With

With sh 'This loop does the replacing
Set LookUpRng = Sheet1.Range("A1:V306")
RowNum = 1

For i = FirstRow To LastRow
ArtNum = sh.Cells(i, ArtCol)
.Cells(ArtNum) = IsText
RowNum = Application.Match(ArtNum, Sheet1.Range("A:A"), 0)
If IsError(RowNum) Then
CellVal = "Error"
End If
Sheet1.Rows(RowNum).Copy
sh.Rows(i).PasteSpecial xlValues
Next i
End With

Application.ScreenUpdating = True

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Strange cut and paste result between worksheets

Hi,

I would make complete sense if you looked at the 4th to last lines of your
code

sh.Rows(i).PasteSpecial xlValues

and that line is saying paste the values. If you change that to this

sh.Rows(i).PasteSpecial Paste:=xlPasteFormulas

it will paste formula

Mike

"elf27" wrote:

Another situation where I'm cutting and pasting between different worksheets.
The problem is that for some reason, the data copied FROM the source sheet
(sheet1) becomes values only on the paste sheet (sh) AND the source sheet.
Doesn't make any sense to me. I've checked all my other procedures and
narrowed it down to this one.
Any ideas?

--------------------------------------------
Public Sub SyncAESheet()
Dim ArtCol As Long
Dim i As Long
Dim FirstRow As Variant
Dim LastRow As Variant
Dim CellVal As Long
Dim RowNum As Long
Dim ArtNum As Long
Dim LookUpRng As Range
Dim sh As Worksheet

Application.ScreenUpdating = False

Set sh = ActiveSheet
ArtCol = 1 'means col A

With sh ' This loop finds the first and last rows
i = 1
Do Until FirstRow < Empty
If IsNumeric(.Cells(i, "A")) Then
If .Cells(i, "A").Value 0 Then
FirstRow = i
End If
ElseIf i 50 Then FirstRow = 1
Else: FirstRow = Empty
End If
i = i + 1
Loop
i = FirstRow
Do Until LastRow < Empty
If .Cells(i + 1, "A").Value = "" Then
LastRow = i
ElseIf .Cells(i + 2, "A").Value = "" Then
LastRow = i + 1
Else: LastRow = Empty
i = i + 1
End If
Loop
End With

With sh 'This loop does the replacing
Set LookUpRng = Sheet1.Range("A1:V306")
RowNum = 1

For i = FirstRow To LastRow
ArtNum = sh.Cells(i, ArtCol)
.Cells(ArtNum) = IsText
RowNum = Application.Match(ArtNum, Sheet1.Range("A:A"), 0)
If IsError(RowNum) Then
CellVal = "Error"
End If
Sheet1.Rows(RowNum).Copy
sh.Rows(i).PasteSpecial xlValues
Next i
End With

Application.ScreenUpdating = True

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Strange cut and paste result between worksheets

Mike,

Nope. As I mentioned, I want to past values in to the destination worksheet.
That is why it's paste values in the place you pointed out.
I do not know why it's changing this on the source worksheet. That's the
problem, the source worksheet.

I changed it to pastefomulas just to try it out and it did not solve the
problem. For some reason the source sheet still goes to static cells from
formulas.

"Mike H" wrote:

Hi,

I would make complete sense if you looked at the 4th to last lines of your
code

sh.Rows(i).PasteSpecial xlValues

and that line is saying paste the values. If you change that to this

sh.Rows(i).PasteSpecial Paste:=xlPasteFormulas

it will paste formula

Mike

"elf27" wrote:

Another situation where I'm cutting and pasting between different worksheets.
The problem is that for some reason, the data copied FROM the source sheet
(sheet1) becomes values only on the paste sheet (sh) AND the source sheet.
Doesn't make any sense to me. I've checked all my other procedures and
narrowed it down to this one.
Any ideas?

--------------------------------------------
Public Sub SyncAESheet()
Dim ArtCol As Long
Dim i As Long
Dim FirstRow As Variant
Dim LastRow As Variant
Dim CellVal As Long
Dim RowNum As Long
Dim ArtNum As Long
Dim LookUpRng As Range
Dim sh As Worksheet

Application.ScreenUpdating = False

Set sh = ActiveSheet
ArtCol = 1 'means col A

With sh ' This loop finds the first and last rows
i = 1
Do Until FirstRow < Empty
If IsNumeric(.Cells(i, "A")) Then
If .Cells(i, "A").Value 0 Then
FirstRow = i
End If
ElseIf i 50 Then FirstRow = 1
Else: FirstRow = Empty
End If
i = i + 1
Loop
i = FirstRow
Do Until LastRow < Empty
If .Cells(i + 1, "A").Value = "" Then
LastRow = i
ElseIf .Cells(i + 2, "A").Value = "" Then
LastRow = i + 1
Else: LastRow = Empty
i = i + 1
End If
Loop
End With

With sh 'This loop does the replacing
Set LookUpRng = Sheet1.Range("A1:V306")
RowNum = 1

For i = FirstRow To LastRow
ArtNum = sh.Cells(i, ArtCol)
.Cells(ArtNum) = IsText
RowNum = Application.Match(ArtNum, Sheet1.Range("A:A"), 0)
If IsError(RowNum) Then
CellVal = "Error"
End If
Sheet1.Rows(RowNum).Copy
sh.Rows(i).PasteSpecial xlValues
Next i
End With

Application.ScreenUpdating = True

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Strange cut and paste result between worksheets

Sh is set to the activesheet.

What's the name of the activesheet?
What's the name of the sheet with codename Sheet1?

Could it be that they're the same?

elf27 wrote:

Another situation where I'm cutting and pasting between different worksheets.
The problem is that for some reason, the data copied FROM the source sheet
(sheet1) becomes values only on the paste sheet (sh) AND the source sheet.
Doesn't make any sense to me. I've checked all my other procedures and
narrowed it down to this one.
Any ideas?

--------------------------------------------
Public Sub SyncAESheet()
Dim ArtCol As Long
Dim i As Long
Dim FirstRow As Variant
Dim LastRow As Variant
Dim CellVal As Long
Dim RowNum As Long
Dim ArtNum As Long
Dim LookUpRng As Range
Dim sh As Worksheet

Application.ScreenUpdating = False

Set sh = ActiveSheet
ArtCol = 1 'means col A

With sh ' This loop finds the first and last rows
i = 1
Do Until FirstRow < Empty
If IsNumeric(.Cells(i, "A")) Then
If .Cells(i, "A").Value 0 Then
FirstRow = i
End If
ElseIf i 50 Then FirstRow = 1
Else: FirstRow = Empty
End If
i = i + 1
Loop
i = FirstRow
Do Until LastRow < Empty
If .Cells(i + 1, "A").Value = "" Then
LastRow = i
ElseIf .Cells(i + 2, "A").Value = "" Then
LastRow = i + 1
Else: LastRow = Empty
i = i + 1
End If
Loop
End With

With sh 'This loop does the replacing
Set LookUpRng = Sheet1.Range("A1:V306")
RowNum = 1

For i = FirstRow To LastRow
ArtNum = sh.Cells(i, ArtCol)
.Cells(ArtNum) = IsText
RowNum = Application.Match(ArtNum, Sheet1.Range("A:A"), 0)
If IsError(RowNum) Then
CellVal = "Error"
End If
Sheet1.Rows(RowNum).Copy
sh.Rows(i).PasteSpecial xlValues
Next i
End With

Application.ScreenUpdating = True

End Sub


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Strange cut and paste result between worksheets

There are four sheets that become activesheet. They are different names of
people. Ex: "Jones, John"

Sheet 1 is called "Master Worksheet"

So you think that the placement of the sh = activesheet makes it so that it
pastes to both sheet1 and the other sheets?



"Dave Peterson" wrote:

Sh is set to the activesheet.

What's the name of the activesheet?
What's the name of the sheet with codename Sheet1?

Could it be that they're the same?

elf27 wrote:

Another situation where I'm cutting and pasting between different worksheets.
The problem is that for some reason, the data copied FROM the source sheet
(sheet1) becomes values only on the paste sheet (sh) AND the source sheet.
Doesn't make any sense to me. I've checked all my other procedures and
narrowed it down to this one.
Any ideas?

--------------------------------------------
Public Sub SyncAESheet()
Dim ArtCol As Long
Dim i As Long
Dim FirstRow As Variant
Dim LastRow As Variant
Dim CellVal As Long
Dim RowNum As Long
Dim ArtNum As Long
Dim LookUpRng As Range
Dim sh As Worksheet

Application.ScreenUpdating = False

Set sh = ActiveSheet
ArtCol = 1 'means col A

With sh ' This loop finds the first and last rows
i = 1
Do Until FirstRow < Empty
If IsNumeric(.Cells(i, "A")) Then
If .Cells(i, "A").Value 0 Then
FirstRow = i
End If
ElseIf i 50 Then FirstRow = 1
Else: FirstRow = Empty
End If
i = i + 1
Loop
i = FirstRow
Do Until LastRow < Empty
If .Cells(i + 1, "A").Value = "" Then
LastRow = i
ElseIf .Cells(i + 2, "A").Value = "" Then
LastRow = i + 1
Else: LastRow = Empty
i = i + 1
End If
Loop
End With

With sh 'This loop does the replacing
Set LookUpRng = Sheet1.Range("A1:V306")
RowNum = 1

For i = FirstRow To LastRow
ArtNum = sh.Cells(i, ArtCol)
.Cells(ArtNum) = IsText
RowNum = Application.Match(ArtNum, Sheet1.Range("A:A"), 0)
If IsError(RowNum) Then
CellVal = "Error"
End If
Sheet1.Rows(RowNum).Copy
sh.Rows(i).PasteSpecial xlValues
Next i
End With

Application.ScreenUpdating = True

End Sub


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Strange cut and paste result between worksheets

Nope.

I'm guessing (and I could be wrong) that you're starting on the sheet that gets
pasted.

So it's just doing a copy|paste special|values right on top of itself.

Add a line to make sure that can't happen:

Set sh = ActiveSheet
if sh.name = sheet1.name then
msgbox "Don't start on this sheet"
exit sub
end if

And see what happens.

Maybe even a msgbox to see what's happening while you're debugging:
msgbox sh.name & vblf & sheet1.name


elf27 wrote:

There are four sheets that become activesheet. They are different names of
people. Ex: "Jones, John"

Sheet 1 is called "Master Worksheet"

So you think that the placement of the sh = activesheet makes it so that it
pastes to both sheet1 and the other sheets?

"Dave Peterson" wrote:

Sh is set to the activesheet.

What's the name of the activesheet?
What's the name of the sheet with codename Sheet1?

Could it be that they're the same?

elf27 wrote:

Another situation where I'm cutting and pasting between different worksheets.
The problem is that for some reason, the data copied FROM the source sheet
(sheet1) becomes values only on the paste sheet (sh) AND the source sheet.
Doesn't make any sense to me. I've checked all my other procedures and
narrowed it down to this one.
Any ideas?

--------------------------------------------
Public Sub SyncAESheet()
Dim ArtCol As Long
Dim i As Long
Dim FirstRow As Variant
Dim LastRow As Variant
Dim CellVal As Long
Dim RowNum As Long
Dim ArtNum As Long
Dim LookUpRng As Range
Dim sh As Worksheet

Application.ScreenUpdating = False

Set sh = ActiveSheet
ArtCol = 1 'means col A

With sh ' This loop finds the first and last rows
i = 1
Do Until FirstRow < Empty
If IsNumeric(.Cells(i, "A")) Then
If .Cells(i, "A").Value 0 Then
FirstRow = i
End If
ElseIf i 50 Then FirstRow = 1
Else: FirstRow = Empty
End If
i = i + 1
Loop
i = FirstRow
Do Until LastRow < Empty
If .Cells(i + 1, "A").Value = "" Then
LastRow = i
ElseIf .Cells(i + 2, "A").Value = "" Then
LastRow = i + 1
Else: LastRow = Empty
i = i + 1
End If
Loop
End With

With sh 'This loop does the replacing
Set LookUpRng = Sheet1.Range("A1:V306")
RowNum = 1

For i = FirstRow To LastRow
ArtNum = sh.Cells(i, ArtCol)
.Cells(ArtNum) = IsText
RowNum = Application.Match(ArtNum, Sheet1.Range("A:A"), 0)
If IsError(RowNum) Then
CellVal = "Error"
End If
Sheet1.Rows(RowNum).Copy
sh.Rows(i).PasteSpecial xlValues
Next i
End With

Application.ScreenUpdating = True

End Sub


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Strange cut and paste result between worksheets

Dave,

Thanks! Another macro started this one on sheet1 and that was the problem.


"Dave Peterson" wrote:

Nope.

I'm guessing (and I could be wrong) that you're starting on the sheet that gets
pasted.

So it's just doing a copy|paste special|values right on top of itself.

Add a line to make sure that can't happen:

Set sh = ActiveSheet
if sh.name = sheet1.name then
msgbox "Don't start on this sheet"
exit sub
end if

And see what happens.

Maybe even a msgbox to see what's happening while you're debugging:
msgbox sh.name & vblf & sheet1.name


elf27 wrote:

There are four sheets that become activesheet. They are different names of
people. Ex: "Jones, John"

Sheet 1 is called "Master Worksheet"

So you think that the placement of the sh = activesheet makes it so that it
pastes to both sheet1 and the other sheets?

"Dave Peterson" wrote:

Sh is set to the activesheet.

What's the name of the activesheet?
What's the name of the sheet with codename Sheet1?

Could it be that they're the same?

elf27 wrote:

Another situation where I'm cutting and pasting between different worksheets.
The problem is that for some reason, the data copied FROM the source sheet
(sheet1) becomes values only on the paste sheet (sh) AND the source sheet.
Doesn't make any sense to me. I've checked all my other procedures and
narrowed it down to this one.
Any ideas?

--------------------------------------------
Public Sub SyncAESheet()
Dim ArtCol As Long
Dim i As Long
Dim FirstRow As Variant
Dim LastRow As Variant
Dim CellVal As Long
Dim RowNum As Long
Dim ArtNum As Long
Dim LookUpRng As Range
Dim sh As Worksheet

Application.ScreenUpdating = False

Set sh = ActiveSheet
ArtCol = 1 'means col A

With sh ' This loop finds the first and last rows
i = 1
Do Until FirstRow < Empty
If IsNumeric(.Cells(i, "A")) Then
If .Cells(i, "A").Value 0 Then
FirstRow = i
End If
ElseIf i 50 Then FirstRow = 1
Else: FirstRow = Empty
End If
i = i + 1
Loop
i = FirstRow
Do Until LastRow < Empty
If .Cells(i + 1, "A").Value = "" Then
LastRow = i
ElseIf .Cells(i + 2, "A").Value = "" Then
LastRow = i + 1
Else: LastRow = Empty
i = i + 1
End If
Loop
End With

With sh 'This loop does the replacing
Set LookUpRng = Sheet1.Range("A1:V306")
RowNum = 1

For i = FirstRow To LastRow
ArtNum = sh.Cells(i, ArtCol)
.Cells(ArtNum) = IsText
RowNum = Application.Match(ArtNum, Sheet1.Range("A:A"), 0)
If IsError(RowNum) Then
CellVal = "Error"
End If
Sheet1.Rows(RowNum).Copy
sh.Rows(i).PasteSpecial xlValues
Next i
End With

Application.ScreenUpdating = True

End Sub

--

Dave Peterson


--

Dave Peterson

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
why this strange result with vlookup Amin Excel Worksheet Functions 3 April 23rd 10 12:16 AM
SUMIF, wrong result, strange behaviour Werner Rohrmoser Excel Worksheet Functions 5 April 23rd 09 05:11 PM
Pivot table strange result prufrock Excel Discussion (Misc queries) 0 February 23rd 07 04:40 PM
Strange result in Excel 2000 ibertram Excel Discussion (Misc queries) 4 November 12th 05 01:48 PM
Switch() causes strange ADO result onedaywhen[_2_] Excel Programming 10 December 13th 04 10:36 AM


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