Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Copying a Cell

I'm trying to find a cell with a string of "SALES" and then copy it 2
columns over. Below is my FindCell function and CopyCell sub. I think
FindCell is ok, but CopyCell sub isn't coping the cell. Any ideas?

Sub CopyCell()
Dim cell As Range
Set cell = FindCell("SALES", Sheets(1).Cells)
If cell Is Nothing Then
'action to take of no match
Else
cell.Offset(0, 2).Copy Worksheets("Sheet1").Range("AT4")
End If
End Sub

Function FindCell(searchFor As String, _
searchRange As Range) As Range

Application.DisplayAlerts = False
With searchRange

Set FindCell = .Find(what:=searchFor, After:=.Cells(.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

End With
End Function


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Copying a Cell

Hi Scott,

Since Sheets(1) may or my not be the same as Sheets("Sheet1"),. it is
probably advisable to replace the forner with latter.

I'm trying to find a cell with a string of "SALES" and then copy it 2
columns over.


The code as written copies the "SALES" cell (offset by 2 columns) to AT4.
Since that is not what you appear to expect, it may be that the copy
operation is taking place but you are looking in the wrong place.

If AT4 is in fact the correct copy destination, then I would simply make the
Sheets(1) === Sheets("Sheet1") amendment and verify that the copy operation
is successful.

If the intended destination is, however, the found cell offset by 2 columns,
are you sure that you want to copy the contents of the found cell, i.e that
both cells should read "SALES"? If this really is the case then you could
simplify the code with:

cell(1, 2).Value = cell.Value


---
Regards,
Norman



"scott" wrote in message
...
I'm trying to find a cell with a string of "SALES" and then copy it 2
columns over. Below is my FindCell function and CopyCell sub. I think
FindCell is ok, but CopyCell sub isn't coping the cell. Any ideas?

Sub CopyCell()
Dim cell As Range
Set cell = FindCell("SALES", Sheets(1).Cells)
If cell Is Nothing Then
'action to take of no match
Else
cell.Offset(0, 2).Copy Worksheets("Sheet1").Range("AT4")
End If
End Sub

Function FindCell(searchFor As String, _
searchRange As Range) As Range

Application.DisplayAlerts = False
With searchRange

Set FindCell = .Find(what:=searchFor, After:=.Cells(.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

End With
End Function



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Copying a Cell

Sub CopyCell()
Dim cell As Range
Set cell = FindCell("SALES", Sheets("Sheet1").Cells()
'this will search the entire sheet until it finds the first match
'if you have a smaller range replace -- .Cells() -- with say
..Range("A1:E100")
If cell Is Nothing Then
'action to take of no match
Else
cell.Copy Destination:=cell.offset(0,2)
End If
End Sub

"scott" wrote:

I'm trying to find a cell with a string of "SALES" and then copy it 2
columns over. Below is my FindCell function and CopyCell sub. I think
FindCell is ok, but CopyCell sub isn't coping the cell. Any ideas?

Sub CopyCell()
Dim cell As Range
Set cell = FindCell("SALES", Sheets(1).Cells)
If cell Is Nothing Then
'action to take of no match
Else
cell.Offset(0, 2).Copy Worksheets("Sheet1").Range("AT4")
End If
End Sub

Function FindCell(searchFor As String, _
searchRange As Range) As Range

Application.DisplayAlerts = False
With searchRange

Set FindCell = .Find(what:=searchFor, After:=.Cells(.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

End With
End Function



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
Copying cell contents from many cells and pasting into one cell MDN Excel Discussion (Misc queries) 7 December 10th 07 08:56 PM
Copying format to a new cell, w/o overwriting destination cell contents James C Excel Discussion (Misc queries) 1 October 18th 05 08:02 PM
copying the function contained within a cell to anouther cell. DMB Excel Worksheet Functions 2 September 1st 05 05:49 PM
Copying excel format from cell to cell Loopy Darren Excel Discussion (Misc queries) 2 April 12th 05 04:29 PM
Copying data down to next dirty cell, then copying that data slarson Excel Programming 0 September 15th 03 09:19 PM


All times are GMT +1. The time now is 08:58 PM.

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"