View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default trouble with macro

First, you use xlTextValues, but it sounds like you are looking for a
currency value (xlNumbers)? If that were corrected or is correct, then

you have .Range("B19:57")
which should be .Range("B19:B57") It that were corrected, then

right now it copies columns A:D to A and then copies B to D

It uses column B in the Pending WS to determine the next available column.

You say you want to copy A, D and I assume B (the currency value) to column
B of Pending - doesn't make much sense - 3 cells to 1.

Also, it assumes the Daily Balance Today.xls is the activeworkbook when it
is run and that Pending and Short.xls is closed.

Perhaps the fix is

Sub copydata()
Dim rng As Range, rng1 As Range, rng2 As Range
Dim rng3 As Range

With Worksheets("Data Input")
Set rng = .Range("B19:B57").SpecialCells(xlConstants, xlNumbers)
if rng.count 1 then
Msgbox "More than one row is found - exiting"
exit sub
End if
If Not rng Is Nothing Then
Set rng1 = Intersect(rng.EntireRow, .Columns(1).Resize(, 2))
Set rng2 = Intersect(rng.EntireRow, .Columns(4))
Else
Exit Sub
End If
End With

Dim bk as Workbook
set bk = Workbooks.Open(C:\Pending and Short Log\Pending and Short.xls")
set rng3 = bk.Worksheets("Pending").Cells(Rows.Count, 2).End(xlUp)(2)

rng1.Copy rng3.Offset(0, -1)
rng2.Copy rng3.Offset(0, 2)

End Sub


--
Regards,
Tom Ogilvy


"glensfallslady" wrote in message
...
I have two workbooks and am trying to copy the currency value (if entered)
in
col B, in rows 19 - 57 only from the "Data Input" WS in WB "Daily Balance
Today" and copy those values to the "Pending" WS in the "Pending and
Short"
WB into the next availabel cell in col C. This workbook is a running
total
so I need to add the information to the bottom of the spreadsheet. If
values
are copied, I need to copy the text from Col A and the date in Col D from
the
Data Input WS and copy that text to Col B in the Pending WS on the same
row
as the currency value. This code is not working for me and I'm not sure
what
is wrong. Thanks in advance for your assistance.


Sub copydata()
Dim rng As Range, rng1 As Range, rng2 As Range
Dim rng3 As Range

With Worksheets("Data Input")
Set rng = .Range("B19:57").SpecialCells(xlConstants, xlTextValues)
If Not rng Is Nothing Then
Set rng1 = Intersect(rng.EntireRow, .Columns(1).Resize(, 4))
Set rng2 = Intersect(rng.EntireRow, .Columns(2))
Else
Exit Sub
End If
End With

Dim bk as Workbook
set bk = Workbooks.Open(C:\Pending and Short Log\Pending and Short.xls")
set rng3 = bk.Worksheets("Pending").Cells(Rows.Count, 2).End(xlUp)(2)

rng1.Copy rng3.Offset(0, -1)
rng2.Copy rng3.Offset(0, 2)

End Sub