Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 94
Default Help Modifying Macro from Dave Peterson

Hello Dave,

I try to look at past postings and modify existing macros before asking
questions, but I couldnt get this one to work and was wondering if you could
help me since you originally helped this user set-up this application.

Im looking to do something very similar to what this poster requested
only just one portion. It appears this macro is matching two values from the
main sheet and pasting to a second sheet and then also pasting over the value
for just one column for the unmatched. Thats the portion Im looking to
expand on I really dont need any values brought over for the matched cells.

I have two workbooks Master Reports and Location Reports. Basically the If
IsError(res) Then would be the portion Id need code for and the only part
Id like to modify. Id like it to do the same thing meaning find next empty
row down in D and again write the value, but Im looking to copy over the
entire unmatched row from Master Reports Report Log to that next down cell
starting with column D in Location Reports.

I tried to insert my sheets and columns in the code below and hopefully I
did in a way where you can tell what Im looking for. Ive also added notes
to the portion Im looking to modify and hopefully this will provide a bit
further detail.

Thanks in advance Jenny B.


Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xls)
.Worksheets("Report Log).Range("A2:A2000)
Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000)

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)

If IsError(res) Then

With WkbkBRng.Parent
.Cells(.Rows.Count, "d).End(xlUp).Offset(1, 0).Value _
= myCell.Value
looking to have this copy over the value from Master Reports to Location
Reports
and copy the full row not just one cell
End With
Else
If WkbkBRng(res).Offset(0, 4).Value < "" Then
myCell.Offset(0, 1).Copy _ dont need this portion

End If
End If
Next myCell

wkbkb.ActiveWorkbook.Close savechanges:=True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function



  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Help Modifying Macro from Dave Peterson

First, if you look at your post, you'll see a bunch of funny characters in it.
I bet that they're caused by composing in MSWord, then copy|pasting to your
message.

This makes it more difficult to read and edit the code. You may want to use a
plain text editor (NotePad???) to make it easier for potential responders.

And maybe this untested, but compiled code is what you want:

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String
Dim DestCell As Range

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xls") _
.Worksheets("Report Log").Range("A2:A2000")

Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000")

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)
If IsError(res) Then
'get ready to paste into Sheet1 at the bottom of column A
With WkbkBRng.Parent
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
myCell.EntireRow.Copy _
Destination:=DestCell
End With
End If
Next myCell

Application.ScreenUpdating = True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function

I did remove the .close (and save). I wasn't sure if you really wanted that.

Jenny B. wrote:

Hello Dave,

I try to look at past postings and modify existing macros before asking
questions, but I couldnt get this one to work and was wondering if you could
help me since you originally helped this user set-up this application.

Im looking to do something very similar to what this poster requested
only just one portion. It appears this macro is matching two values from the
main sheet and pasting to a second sheet and then also pasting over the value
for just one column for the unmatched. Thats the portion Im looking to
expand on I really dont need any values brought over for the matched cells.

I have two workbooks Master Reports and Location Reports. Basically the If
IsError(res) Then would be the portion Id need code for and the only part
Id like to modify. Id like it to do the same thing meaning find next empty
row down in D and again write the value, but Im looking to copy over the
entire unmatched row from Master Reports Report Log to that next down cell
starting with column D in Location Reports.

I tried to insert my sheets and columns in the code below and hopefully I
did in a way where you can tell what Im looking for. Ive also added notes
to the portion Im looking to modify and hopefully this will provide a bit
further detail.

Thanks in advance Jenny B.

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xls)
.Worksheets("Report Log).Range("A2:A2000)
Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000)

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)

If IsError(res) Then

With WkbkBRng.Parent
.Cells(.Rows.Count, "d).End(xlUp).Offset(1, 0).Value _
= myCell.Value
looking to have this copy over the value from Master Reports to Location
Reports
and copy the full row not just one cell
End With
Else
If WkbkBRng(res).Offset(0, 4).Value < "" Then
myCell.Offset(0, 1).Copy _ dont need this portion

End If
End If
Next myCell

wkbkb.ActiveWorkbook.Close savechanges:=True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 94
Default Help Modifying Macro from Dave Peterson

Hello Dave,

Thank you for the tip on my post. I was composing this in Outlook and
thought the offending party adding the symbols was after I pasted it in the
Disscussion Group Window - my error.

What you wrote works great, but is there any way to have it paste just the
values vs. the exact formatting on all the cells? I want the whole line of
data like now, but I'm just looking to paste over just the values since the
one sheet has different formatting then the other.

Thank you very much and appreciate your help - Jenny B.

"Dave Peterson" wrote:

First, if you look at your post, you'll see a bunch of funny characters in it.
I bet that they're caused by composing in MSWord, then copy|pasting to your
message.

This makes it more difficult to read and edit the code. You may want to use a
plain text editor (NotePad???) to make it easier for potential responders.

And maybe this untested, but compiled code is what you want:

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String
Dim DestCell As Range

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xls") _
.Worksheets("Report Log").Range("A2:A2000")

Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000")

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)
If IsError(res) Then
'get ready to paste into Sheet1 at the bottom of column A
With WkbkBRng.Parent
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
myCell.EntireRow.Copy _
Destination:=DestCell
End With
End If
Next myCell

Application.ScreenUpdating = True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function

I did remove the .close (and save). I wasn't sure if you really wanted that.

Jenny B. wrote:

Hello Dave,

I try to look at past postings and modify existing macros before asking
questions, but I couldnât get this one to work and was wondering if you could
help me since you originally helped this user set-up this application.

Iâm looking to do something very similar to what this poster requested â
only just one portion. It appears this macro is matching two values from the
main sheet and pasting to a second sheet and then also pasting over the value
for just one column for the unmatched. Thatâs the portion Iâm looking to
expand on â I really donât need any values brought over for the matched cells.

I have two workbooks Master Reports and Location Reports. Basically the âœIf
IsError(res) Then❠would be the portion Iâd need code for and the only part
Iâd like to modify. Iâd like it to do the same thing meaning find next empty
row down in âœD❠and again write the value, but Iâm looking to copy over the
entire unmatched row from Master Reports âœReport Log❠to that next down cell
starting with column âœD❠in Location Reports.

I tried to insert my sheets and columns in the code below and hopefully I
did in a way where you can tell what Iâm looking for. Iâve also added notes
to the portion Iâm looking to modify and hopefully this will provide a bit
further detail.

Thanks in advance â Jenny B.

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xlsâ)
.Worksheets("Report Logâ).Range("A2:A2000â)
Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000â)

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)

If IsError(res) Then

With WkbkBRng.Parent
.Cells(.Rows.Count, "dâ).End(xlUp).Offset(1, 0).Value _
= myCell.Value
â˜looking to have this copy over the value from Master Reports to Location
Reports
â˜and copy the full row not just one cell
End With
Else
If WkbkBRng(res).Offset(0, 4).Value < "" Then
myCell.Offset(0, 1).Copy _ ☠donât need this portion

End If
End If
Next myCell

wkbkb.ActiveWorkbook.Close savechanges:=True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Help Modifying Macro from Dave Peterson

myCell.EntireRow.Copy _
Destination:=DestCell


becomes

myCell.EntireRow.Copy
destcell.pastespecial paste:=xlpastevalues




Jenny B. wrote:

Hello Dave,

Thank you for the tip on my post. I was composing this in Outlook and
thought the offending party adding the symbols was after I pasted it in the
Disscussion Group Window - my error.

What you wrote works great, but is there any way to have it paste just the
values vs. the exact formatting on all the cells? I want the whole line of
data like now, but I'm just looking to paste over just the values since the
one sheet has different formatting then the other.

Thank you very much and appreciate your help - Jenny B.

"Dave Peterson" wrote:

First, if you look at your post, you'll see a bunch of funny characters in it.
I bet that they're caused by composing in MSWord, then copy|pasting to your
message.

This makes it more difficult to read and edit the code. You may want to use a
plain text editor (NotePad???) to make it easier for potential responders.

And maybe this untested, but compiled code is what you want:

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String
Dim DestCell As Range

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xls") _
.Worksheets("Report Log").Range("A2:A2000")

Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000")

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)
If IsError(res) Then
'get ready to paste into Sheet1 at the bottom of column A
With WkbkBRng.Parent
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
myCell.EntireRow.Copy _
Destination:=DestCell
End With
End If
Next myCell

Application.ScreenUpdating = True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function

I did remove the .close (and save). I wasn't sure if you really wanted that.

Jenny B. wrote:

Hello Dave,

I try to look at past postings and modify existing macros before asking
questions, but I couldnât get this one to work and was wondering if you could
help me since you originally helped this user set-up this application.

Iâm looking to do something very similar to what this poster requested â
only just one portion. It appears this macro is matching two values from the
main sheet and pasting to a second sheet and then also pasting over the value
for just one column for the unmatched. Thatâs the portion Iâm looking to
expand on â I really donât need any values brought over for the matched cells.

I have two workbooks Master Reports and Location Reports. Basically the âœIf
IsError(res) Then❠would be the portion Iâd need code for and the only part
Iâd like to modify. Iâd like it to do the same thing meaning find next empty
row down in âœD❠and again write the value, but Iâm looking to copy over the
entire unmatched row from Master Reports âœReport Log❠to that next down cell
starting with column âœD❠in Location Reports.

I tried to insert my sheets and columns in the code below and hopefully I
did in a way where you can tell what Iâm looking for. Iâve also added notes
to the portion Iâm looking to modify and hopefully this will provide a bit
further detail.

Thanks in advance â Jenny B.

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xlsâ)
.Worksheets("Report Logâ).Range("A2:A2000â)
Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000â)

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)

If IsError(res) Then

With WkbkBRng.Parent
.Cells(.Rows.Count, "dâ).End(xlUp).Offset(1, 0).Value _
= myCell.Value
â˜looking to have this copy over the value from Master Reports to Location
Reports
â˜and copy the full row not just one cell
End With
Else
If WkbkBRng(res).Offset(0, 4).Value < "" Then
myCell.Offset(0, 1).Copy _ ☠donât need this portion

End If
End If
Next myCell

wkbkb.ActiveWorkbook.Close savechanges:=True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 94
Default Help Modifying Macro from Dave Peterson

Thank you very much - works great!

"Dave Peterson" wrote:

myCell.EntireRow.Copy _
Destination:=DestCell


becomes

myCell.EntireRow.Copy
destcell.pastespecial paste:=xlpastevalues




Jenny B. wrote:

Hello Dave,

Thank you for the tip on my post. I was composing this in Outlook and
thought the offending party adding the symbols was after I pasted it in the
Disscussion Group Window - my error.

What you wrote works great, but is there any way to have it paste just the
values vs. the exact formatting on all the cells? I want the whole line of
data like now, but I'm just looking to paste over just the values since the
one sheet has different formatting then the other.

Thank you very much and appreciate your help - Jenny B.

"Dave Peterson" wrote:

First, if you look at your post, you'll see a bunch of funny characters in it.
I bet that they're caused by composing in MSWord, then copy|pasting to your
message.

This makes it more difficult to read and edit the code. You may want to use a
plain text editor (NotePad???) to make it easier for potential responders.

And maybe this untested, but compiled code is what you want:

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String
Dim DestCell As Range

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xls") _
.Worksheets("Report Log").Range("A2:A2000")

Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000")

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)
If IsError(res) Then
'get ready to paste into Sheet1 at the bottom of column A
With WkbkBRng.Parent
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
myCell.EntireRow.Copy _
Destination:=DestCell
End With
End If
Next myCell

Application.ScreenUpdating = True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function

I did remove the .close (and save). I wasn't sure if you really wanted that.

Jenny B. wrote:

Hello Dave,

I try to look at past postings and modify existing macros before asking
questions, but I couldnââ¬â¢t get this one to work and was wondering if you could
help me since you originally helped this user set-up this application.

Iââ¬â¢m looking to do something very similar to what this poster requested ââ¬âœ
only just one portion. It appears this macro is matching two values from the
main sheet and pasting to a second sheet and then also pasting over the value
for just one column for the unmatched. Thatââ¬â¢s the portion Iââ¬â¢m looking to
expand on ââ¬âœ I really donââ¬â¢t need any values brought over for the matched cells.

I have two workbooks Master Reports and Location Reports. Basically the ââ¬ÅIf
IsError(res) Thenââ¬Â would be the portion Iââ¬â¢d need code for and the only part
Iââ¬â¢d like to modify. Iââ¬â¢d like it to do the same thing meaning find next empty
row down in ââ¬ÅDââ¬Â and again write the value, but Iââ¬â¢m looking to copy over the
entire unmatched row from Master Reports ââ¬ÅReport Logââ¬Â to that next down cell
starting with column ââ¬ÅDââ¬Â in Location Reports.

I tried to insert my sheets and columns in the code below and hopefully I
did in a way where you can tell what Iââ¬â¢m looking for. Iââ¬â¢ve also added notes
to the portion Iââ¬â¢m looking to modify and hopefully this will provide a bit
further detail.

Thanks in advance ââ¬âœ Jenny B.

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xlsââ¬Â)
.Worksheets("Report Logââ¬Â).Range("A2:A2000ââ¬Â )
Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000â⠬)

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)

If IsError(res) Then

With WkbkBRng.Parent
.Cells(.Rows.Count, "dââ¬Â).End(xlUp).Offset(1, 0).Value _
= myCell.Value
ââ¬Ëœlooking to have this copy over the value from Master Reports to Location
Reports
ââ¬Ëœand copy the full row not just one cell
End With
Else
If WkbkBRng(res).Offset(0, 4).Value < "" Then
myCell.Offset(0, 1).Copy _ ââ¬Ëœ donââ¬â¢t need this portion

End If
End If
Next myCell

wkbkb.ActiveWorkbook.Close savechanges:=True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Help Modifying Macro from Dave Peterson

How come I don't see any funny characters in Jenny's post?

I miss out on everything<g

All I see are regular characters in her post and little hollow boxes when I add
CHAR(9)'s in a formula.


Gord

On Sun, 02 Mar 2008 19:56:15 -0600, Dave Peterson
wrote:

First, if you look at your post, you'll see a bunch of funny characters in it.
I bet that they're caused by composing in MSWord, then copy|pasting to your
message.

This makes it more difficult to read and edit the code. You may want to use a
plain text editor (NotePad???) to make it easier for potential responders.

And maybe this untested, but compiled code is what you want:

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String
Dim DestCell As Range

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xls") _
.Worksheets("Report Log").Range("A2:A2000")

Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000")

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)
If IsError(res) Then
'get ready to paste into Sheet1 at the bottom of column A
With WkbkBRng.Parent
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
myCell.EntireRow.Copy _
Destination:=DestCell
End With
End If
Next myCell

Application.ScreenUpdating = True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function

I did remove the .close (and save). I wasn't sure if you really wanted that.

Jenny B. wrote:

Hello Dave,

I try to look at past postings and modify existing macros before asking
questions, but I couldnt get this one to work and was wondering if you could
help me since you originally helped this user set-up this application.

Im looking to do something very similar to what this poster requested
only just one portion. It appears this macro is matching two values from the
main sheet and pasting to a second sheet and then also pasting over the value
for just one column for the unmatched. Thats the portion Im looking to
expand on I really dont need any values brought over for the matched cells.

I have two workbooks Master Reports and Location Reports. Basically the If
IsError(res) Then? would be the portion Id need code for and the only part
Id like to modify. Id like it to do the same thing meaning find next empty
row down in D? and again write the value, but Im looking to copy over the
entire unmatched row from Master Reports Report Log? to that next down cell
starting with column D? in Location Reports.

I tried to insert my sheets and columns in the code below and hopefully I
did in a way where you can tell what Im looking for. Ive also added notes
to the portion Im looking to modify and hopefully this will provide a bit
further detail.

Thanks in advance Jenny B.

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xls?)
.Worksheets("Report Log?).Range("A2:A2000?)
Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000?)

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)

If IsError(res) Then

With WkbkBRng.Parent
.Cells(.Rows.Count, "d?).End(xlUp).Offset(1, 0).Value _
= myCell.Value
looking to have this copy over the value from Master Reports to Location
Reports
and copy the full row not just one cell
End With
Else
If WkbkBRng(res).Offset(0, 4).Value < "" Then
myCell.Offset(0, 1).Copy _ dont need this portion

End If
End If
Next myCell

wkbkb.ActiveWorkbook.Close savechanges:=True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function


  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Help Modifying Macro from Dave Peterson

Maybe it's one of those Canadian fonts where nothing looks funny????

<gd&r

Gord Dibben wrote:

How come I don't see any funny characters in Jenny's post?

I miss out on everything<g

All I see are regular characters in her post and little hollow boxes when I add
CHAR(9)'s in a formula.

Gord

On Sun, 02 Mar 2008 19:56:15 -0600, Dave Peterson
wrote:

First, if you look at your post, you'll see a bunch of funny characters in it.
I bet that they're caused by composing in MSWord, then copy|pasting to your
message.

This makes it more difficult to read and edit the code. You may want to use a
plain text editor (NotePad???) to make it easier for potential responders.

And maybe this untested, but compiled code is what you want:

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String
Dim DestCell As Range

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xls") _
.Worksheets("Report Log").Range("A2:A2000")

Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000")

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)
If IsError(res) Then
'get ready to paste into Sheet1 at the bottom of column A
With WkbkBRng.Parent
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
myCell.EntireRow.Copy _
Destination:=DestCell
End With
End If
Next myCell

Application.ScreenUpdating = True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function

I did remove the .close (and save). I wasn't sure if you really wanted that.

Jenny B. wrote:

Hello Dave,

I try to look at past postings and modify existing macros before asking
questions, but I couldnt get this one to work and was wondering if you could
help me since you originally helped this user set-up this application.

Im looking to do something very similar to what this poster requested
only just one portion. It appears this macro is matching two values from the
main sheet and pasting to a second sheet and then also pasting over the value
for just one column for the unmatched. Thats the portion Im looking to
expand on I really dont need any values brought over for the matched cells.

I have two workbooks Master Reports and Location Reports. Basically the If
IsError(res) Then? would be the portion Id need code for and the only part
Id like to modify. Id like it to do the same thing meaning find next empty
row down in D? and again write the value, but Im looking to copy over the
entire unmatched row from Master Reports Report Log? to that next down cell
starting with column D? in Location Reports.

I tried to insert my sheets and columns in the code below and hopefully I
did in a way where you can tell what Im looking for. Ive also added notes
to the portion Im looking to modify and hopefully this will provide a bit
further detail.

Thanks in advance Jenny B.

Option Explicit
Sub fyCompare()
Dim Msg As String
Dim myPath As String
Dim WkbkARng As Range
Dim WkbkBRng As Range
Dim WkbkB As Workbook
Dim myCell As Range
Dim res As Variant
Dim WkbkBName As String

Msg = "Unable to find"
myPath = "C:\Documents and Settings\Mine\Desktop\"
WkbkBName = "Location Reports.xls"

If WorkbookIsOpen(WkbkBName) = False Then
On Error Resume Next
Set WkbkB = Workbooks.Open(Filename:=myPath & WkbkBName)
If Err.Number < 0 Then
MsgBox Msg & myPath & WkbkBName, vbCritical, "Error"
Err.Clear
Exit Sub
End If
On Error GoTo 0
End If

Application.ScreenUpdating = False

Set WkbkARng = Workbooks("Master Reports.xls?)
.Worksheets("Report Log?).Range("A2:A2000?)
Set WkbkBRng = WkbkB.Worksheets("Sheet1").Range("A2:A2000?)

For Each myCell In WkbkARng.Cells
res = Application.Match(myCell.Value, WkbkBRng, 0)

If IsError(res) Then

With WkbkBRng.Parent
.Cells(.Rows.Count, "d?).End(xlUp).Offset(1, 0).Value _
= myCell.Value
looking to have this copy over the value from Master Reports to Location
Reports
and copy the full row not just one cell
End With
Else
If WkbkBRng(res).Offset(0, 4).Value < "" Then
myCell.Offset(0, 1).Copy _ dont need this portion

End If
End If
Next myCell

wkbkb.ActiveWorkbook.Close savechanges:=True

End Sub

Private Function WorkbookIsOpen(wbName) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbName)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If
On Error GoTo 0
End Function


--

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
Macro Question for Dave Peterson JoeSpareBedroom Excel Discussion (Misc queries) 5 February 14th 07 06:45 PM
Dave Peterson Rich_Patterson Excel Discussion (Misc queries) 2 January 26th 07 08:56 PM
Dave Peterson joelbeveridge Excel Discussion (Misc queries) 1 August 4th 06 02:55 AM
Mr Dave peterson, Please help TUNGANA KURMA RAJU Excel Discussion (Misc queries) 5 December 7th 05 05:11 AM
Dave Peterson atxcomputers Excel Discussion (Misc queries) 12 September 28th 05 06:17 PM


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