Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The following code helps to copy to Visible Cells Only.
What I need is to select any one of the open workbook using a combobox and select a range (visible Cells Only) using Refedit and copy the data and through same combobox and Refedit or another combobox and Refedit select the destination workbook and cell and paste the copied data to the visible cells only. Any Help Please.... Option Explicit Public StartWB As Workbook Public StartWS As Worksheet Public CopyRng As String Public Sub CopyToVisibleOnly1() 'Start with cell selected that you want to copy. Set StartWB = ActiveWorkbook Set StartWS = ActiveSheet CopyRng = Selection.Address 'Call CopyToVisibleOnly2 after a five-second delay. Application.OnTime Now() + TimeValue("0:00:04"), "CopyToVisibleOnly2" End Sub Private Sub CopyToVisibleOnly2() 'Declare local variables. Dim EndWB As Workbook, EndWS As Worksheet Dim Target As Range, CurrCell As Range Dim x As Long, FromCnt As Long On Error GoTo CTVOerr 'Select the range where it should be pasted. Set Target = Application.InputBox _ (Prompt:="Select the first cell in the Paste range", Type:=8) Set EndWB = ActiveWorkbook Set EndWS = ActiveSheet Set CurrCell = Target.Cells(1, 1) Application.ScreenUpdating = False 'Copy the cells from the original workbook, one at a time. StartWB.Activate StartWS.Activate For x = 1 To Range(CopyRng).Count StartWB.Activate StartWS.Activate Range(CopyRng).Cells(x, 1).Copy 'Return to the target workbook. EndWB.Activate EndWS.Activate CurrCell.Activate 'Only cells in visible rows in the selected 'range are pasted. Do While (CurrCell.EntireRow.Hidden = True) Or _ (CurrCell.EntireColumn.Hidden = True) Set CurrCell = CurrCell.Offset(1, 0) Loop CurrCell.Select ActiveSheet.Paste Set CurrCell = CurrCell.Offset(1, 0) Next x Cleanup: 'Free the object variables. Set Target = Nothing Set CurrCell = Nothing Set StartWB = Nothing Set StartWS = Nothing Set EndWB = Nothing Set EndWS = Nothing Application.ScreenUpdating = True Exit Sub CTVOerr: MsgBox Err.Description GoTo Cleanup End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Copy Visible Cells in Sheet with Merged and Hidden Cells | Excel Discussion (Misc queries) | |||
Copy Visible Cells and paste in another workbook visible cells only | Excel Programming | |||
copy visible cells | Excel Worksheet Functions | |||
Copy visible cells only | Excel Programming | |||
Copy visible cells only | Excel Discussion (Misc queries) |