help with copying value and not formula

will1128

Board Regular
Joined
Aug 6, 2010
Messages
70
I'm trying to copy the value of a formula and not the formula from one worksheet to another if and only if the cell is found. I've been able to copy the the column, but I get a #REF error on the 2nd worksheet.

Here's the code:
<code>
Public Function copy_col_to_new_sheet(Col As String) As Range
'Dim Col As String
Dim FoundCell As Range
FindString = Col 'value sent in from the function

If Trim(FindString) <> "" Then
With ActiveWorkbook.Sheets(1).Range("A1:IV65536")
'With ThisWorkbook.Sheets(1).Range("A1:IV65536")
Set FoundCell = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
'if my cell is found copy to 2nd worksheet
If Not FoundCell Is Nothing Then
Application.Goto FoundCell, True
MsgBox FoundCell.Address & FoundCell.Text & " " & "Found in Copy_Col" 'returns cell address
'MsgBox FoundCell.Columns & " " & "Columns" 'returns the column number as a Long
FoundCell.Cells.EntireColumn.Copy ActiveWorkbook.Sheets(2).Columns(FoundCell.Column) 'this works
Else
MsgBox "Nothing found Copy Col To New Sheet"
End If
End With
End If
End Function
<code>
 
I finally understood what you meant by the row and the UsedRange and did decide to use those values instead of the entire column. It makes more sense to only use the rows that are used instead of the all blank rows. I wasn't sure what the UsedRange was until I looked it up. Thank you for you help. I'm learning as I go.
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi I am struggling with this code and want to paste format and formulas.

Sub Macro1()
' This macro takes values in the range myList
' and breaks it in to multiple lists
' and saves them to separate files.
Dim cell As Range
Dim curPath As String
curPath = ActiveWorkbook.Path & "\"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each cell In Range("bizu")
[BU] = cell.Value
Range("myList1").AdvancedFilter Action:=xlFilterCopy, _
Criteriarange:=Range("Criteria"), copyToRange:=Range("bizextract"), unique:=False
Range(Range("bizExtract"), Range("bizExtract").End(xlDown)).Copy
Workbooks.Add
ActiveSheet.Paste
ActiveWorkbook.SaveAs Filename:=curPath & cell.Value & Format(Now, "dmmmyyyy-hhmmss") & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
Range(Range("bizExtract"), Range("bizExtract").End(xlDown)).ClearContents
Next cell

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub
please help
 
Upvote 0

Forum statistics

Threads
1,215,377
Messages
6,124,598
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top